forked from MrBesen/soundboard
saimple sample "editing" working
This commit is contained in:
parent
7246ab94b7
commit
7f3445de54
|
@ -1,7 +1,8 @@
|
||||||
#ifndef EDITSAMPLE_H
|
#pragma once
|
||||||
#define EDITSAMPLE_H
|
|
||||||
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
|
#include <QTimeEdit>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class EditSample;
|
class EditSample;
|
||||||
|
@ -12,11 +13,20 @@ class EditSample : public QDialog
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit EditSample(QWidget *parent = nullptr);
|
explicit EditSample(const std::string& audioFile, QWidget *parent = nullptr);
|
||||||
~EditSample();
|
~EditSample();
|
||||||
|
|
||||||
private:
|
public slots:
|
||||||
Ui::EditSample *ui;
|
void play();
|
||||||
};
|
void stop();
|
||||||
|
|
||||||
#endif // EDITSAMPLE_H
|
private:
|
||||||
|
Ui::EditSample* ui;
|
||||||
|
|
||||||
|
const std::string audioFile;
|
||||||
|
uint64_t getTimeInfo(const QTimeEdit* time) const;
|
||||||
|
|
||||||
|
uint64_t currentposition = 0;
|
||||||
|
|
||||||
|
void setCurrentPosition(uint64_t);
|
||||||
|
};
|
||||||
|
|
|
@ -19,12 +19,14 @@ public:
|
||||||
static void deinitInstance();
|
static void deinitInstance();
|
||||||
|
|
||||||
void addPlayback(const std::string& name, float volume = 1.f, uint64_t beginms = 0, uint64_t endms = 0);
|
void addPlayback(const std::string& name, float volume = 1.f, uint64_t beginms = 0, uint64_t endms = 0);
|
||||||
|
void addPlayback(const std::string& audioDeviceName, const std::string& name, float volume = 1.f, uint64_t beginms = 0, uint64_t endms = 0);
|
||||||
bool addDefaultDevice();
|
bool addDefaultDevice();
|
||||||
bool addDeviceWithName(const std::string& name);
|
bool addDeviceWithName(const std::string& name);
|
||||||
void stopAll();
|
void stopAll();
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
SampleReader* openFile(const std::string& name);
|
SampleReader* openFile(const std::string& name);
|
||||||
|
std::vector<std::string> getOutputs();
|
||||||
|
|
||||||
static std::string FOLDER;
|
static std::string FOLDER;
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -21,6 +21,8 @@ public:
|
||||||
void startDevice();
|
void startDevice();
|
||||||
void cleanupDecoders(); //fertige decoder löschen
|
void cleanupDecoders(); //fertige decoder löschen
|
||||||
|
|
||||||
|
std::string getName() const;
|
||||||
|
|
||||||
// callback
|
// callback
|
||||||
void sound_callback(void* outbuffer, ma_uint32 frameCount);
|
void sound_callback(void* outbuffer, ma_uint32 frameCount);
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,58 @@
|
||||||
#include "editsample.h"
|
#include "editsample.h"
|
||||||
#include "ui_editsample.h"
|
#include "ui_editsample.h"
|
||||||
|
|
||||||
EditSample::EditSample(QWidget *parent) : QDialog(parent), ui(new Ui::EditSample) {
|
#include "sound.h"
|
||||||
|
#include <Log.h>
|
||||||
|
#include <iomanip>
|
||||||
|
|
||||||
|
EditSample::EditSample(const std::string& audioFile_, QWidget *parent) : QDialog(parent), ui(new Ui::EditSample), audioFile(audioFile_) {
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
|
std::vector<std::string> sounddevices = Sound::instance().getOutputs();
|
||||||
|
for(const std::string& dev : sounddevices) {
|
||||||
|
QString qdeviceName = QString::fromStdString(dev);
|
||||||
|
ui->soundOutputselect->addItem(qdeviceName, qdeviceName);
|
||||||
|
}
|
||||||
|
|
||||||
|
QObject::connect(ui->playButton, SIGNAL( clicked() ), this, SLOT( play() ));
|
||||||
|
QObject::connect(ui->stopButton, SIGNAL( clicked() ), this, SLOT( stop() ));
|
||||||
}
|
}
|
||||||
|
|
||||||
EditSample::~EditSample() {
|
EditSample::~EditSample() {
|
||||||
delete ui;
|
delete ui;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditSample::play() {
|
||||||
|
// get audio device
|
||||||
|
std::string devicename = ui->soundOutputselect->currentText().toStdString();
|
||||||
|
|
||||||
|
// get timing info
|
||||||
|
uint64_t startTime = getTimeInfo(ui->startTime);
|
||||||
|
uint64_t lengthTime = getTimeInfo(ui->lengthTime);
|
||||||
|
|
||||||
|
// convert relative time to absolute
|
||||||
|
if(lengthTime != 0) {
|
||||||
|
lengthTime = startTime + lengthTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
Log::info << "play audio: " << std::quoted(audioFile) << " on " << std::quoted(devicename) << " with " << startTime << " and " << lengthTime;
|
||||||
|
Sound::instance().addPlayback(devicename, audioFile, 1.0, startTime, lengthTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditSample::stop() {
|
||||||
|
Sound::instance().stopAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
uint64_t EditSample::getTimeInfo(const QTimeEdit* time) const {
|
||||||
|
QTime timedata = time->time();
|
||||||
|
return (((((
|
||||||
|
(timedata.hour() * 60)
|
||||||
|
+ timedata.minute()) * 60)
|
||||||
|
+ timedata.second()) * 1000)
|
||||||
|
+ timedata.msec());
|
||||||
|
}
|
||||||
|
|
||||||
|
void EditSample::setCurrentPosition(uint64_t cp) {
|
||||||
|
currentposition = cp;
|
||||||
|
|
||||||
|
}
|
|
@ -151,10 +151,11 @@ void MainWindow::addSample() {
|
||||||
std::string file = qfile.toStdString();
|
std::string file = qfile.toStdString();
|
||||||
file = file.substr(file.rfind('/')+1);
|
file = file.substr(file.rfind('/')+1);
|
||||||
Log::info << "selected file: " << file;
|
Log::info << "selected file: " << file;
|
||||||
}
|
|
||||||
|
|
||||||
EditSample esample(this);
|
//spawn edit dialog
|
||||||
esample.exec();
|
EditSample esample(file, this);
|
||||||
|
esample.exec();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -74,6 +74,19 @@ void Sound::addPlayback(const std::string& name, float volume, uint64_t beginms,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Sound::addPlayback(const std::string& audioDeviceName, const std::string& name, float volume, uint64_t beginms, uint64_t endms) {
|
||||||
|
if(volume < 0.00001f)
|
||||||
|
volume = 0.00001f;
|
||||||
|
|
||||||
|
std::lock_guard<std::mutex> lock(devicesMutex);
|
||||||
|
for(SoundDevice* sd : devices) {
|
||||||
|
if(sd->getName() == audioDeviceName) {
|
||||||
|
sd->addPlayback(name, volume, beginms, endms);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool Sound::addDefaultDevice() {
|
bool Sound::addDefaultDevice() {
|
||||||
SoundDevice* sd = SoundDevice::createDevice(&context);
|
SoundDevice* sd = SoundDevice::createDevice(&context);
|
||||||
if(sd) {
|
if(sd) {
|
||||||
|
@ -113,6 +126,16 @@ SampleReader* Sound::openFile(const std::string& name) {
|
||||||
return SampleReader::createSampleReader(FOLDER + name);
|
return SampleReader::createSampleReader(FOLDER + name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<std::string> Sound::getOutputs() {
|
||||||
|
std::lock_guard<std::mutex> lock(devicesMutex);
|
||||||
|
std::vector<std::string> out;
|
||||||
|
out.reserve(devices.size());
|
||||||
|
for(SoundDevice* sd : devices) {
|
||||||
|
out.push_back(sd->getName());
|
||||||
|
}
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
Sound::Sound() {
|
Sound::Sound() {
|
||||||
init();
|
init();
|
||||||
startBackgroundThread();
|
startBackgroundThread();
|
||||||
|
|
|
@ -40,6 +40,9 @@ static ma_uint64 readDecoderandAdd(ma_decoder* decoder, float volume, unsigned i
|
||||||
return frameCountRead;
|
return frameCountRead;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string SoundDevice::getName() const {
|
||||||
|
return device.playback.name;
|
||||||
|
}
|
||||||
|
|
||||||
void SoundDevice::sound_callback(void* outbuffer, ma_uint32 frameCount) {
|
void SoundDevice::sound_callback(void* outbuffer, ma_uint32 frameCount) {
|
||||||
ma_mutex_lock(data.mutex);
|
ma_mutex_lock(data.mutex);
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>400</width>
|
<width>465</width>
|
||||||
<height>300</height>
|
<height>320</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -26,13 +26,6 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QComboBox" name="soundOutputselect">
|
|
||||||
<property name="editable">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
<item>
|
<item>
|
||||||
<layout class="QHBoxLayout" name="timeRow">
|
<layout class="QHBoxLayout" name="timeRow">
|
||||||
<item>
|
<item>
|
||||||
|
@ -65,21 +58,57 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="soundOutputselectLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="soundOutputselectLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>AudioDevice:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="soundOutputselect">
|
||||||
|
<property name="editable">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="buttonLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="playButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Play</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="stopButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Stop</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
|
||||||
|
</property>
|
||||||
|
<property name="centerButtons">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
|
||||||
<widget class="QDialogButtonBox" name="buttonBox">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Horizontal</enum>
|
|
||||||
</property>
|
|
||||||
<property name="standardButtons">
|
|
||||||
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel|QDialogButtonBox::Save</set>
|
|
||||||
</property>
|
|
||||||
<property name="centerButtons">
|
|
||||||
<bool>false</bool>
|
|
||||||
</property>
|
|
||||||
</widget>
|
|
||||||
</item>
|
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
@ -98,8 +127,8 @@
|
||||||
<slot>accept()</slot>
|
<slot>accept()</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel">
|
<hint type="sourcelabel">
|
||||||
<x>248</x>
|
<x>257</x>
|
||||||
<y>254</y>
|
<y>305</y>
|
||||||
</hint>
|
</hint>
|
||||||
<hint type="destinationlabel">
|
<hint type="destinationlabel">
|
||||||
<x>157</x>
|
<x>157</x>
|
||||||
|
@ -114,8 +143,8 @@
|
||||||
<slot>reject()</slot>
|
<slot>reject()</slot>
|
||||||
<hints>
|
<hints>
|
||||||
<hint type="sourcelabel">
|
<hint type="sourcelabel">
|
||||||
<x>316</x>
|
<x>325</x>
|
||||||
<y>260</y>
|
<y>305</y>
|
||||||
</hint>
|
</hint>
|
||||||
<hint type="destinationlabel">
|
<hint type="destinationlabel">
|
||||||
<x>286</x>
|
<x>286</x>
|
||||||
|
@ -123,5 +152,21 @@
|
||||||
</hint>
|
</hint>
|
||||||
</hints>
|
</hints>
|
||||||
</connection>
|
</connection>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>rejected()</signal>
|
||||||
|
<receiver>stopButton</receiver>
|
||||||
|
<slot>click()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>407</x>
|
||||||
|
<y>299</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>132</x>
|
||||||
|
<y>301</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
</connections>
|
</connections>
|
||||||
</ui>
|
</ui>
|
||||||
|
|
Loading…
Reference in New Issue