audio settings kind of works now
parent
1ebc8f04c5
commit
41a591a957
|
@ -143,14 +143,16 @@ void AudioEngine::play(std::shared_ptr<Project> p, int fromPos) {
|
||||||
if (!p) return; // nope
|
if (!p) return; // nope
|
||||||
project = p;
|
project = p;
|
||||||
|
|
||||||
|
// load audio settings
|
||||||
|
sampleRate = AudioConfig::playbackSampleRate;
|
||||||
|
bufferMs = AudioConfig::playbackBufferMs;
|
||||||
|
|
||||||
// stop and reset, then init playback
|
// stop and reset, then init playback
|
||||||
queueValid = false;
|
queueValid = false;
|
||||||
queue.clear();
|
queue.clear();
|
||||||
portLastNoteId.fill(0);
|
portLastNoteId.fill(0);
|
||||||
project->rootGraph->reset();
|
project->rootGraph->reset();
|
||||||
|
|
||||||
sampleRate = AudioConfig::playbackSampleRate;
|
|
||||||
bufferMs = AudioConfig::playbackBufferMs;
|
|
||||||
initAudio();
|
initAudio();
|
||||||
for (auto& b : buffer) {
|
for (auto& b : buffer) {
|
||||||
b.clear();
|
b.clear();
|
||||||
|
@ -196,13 +198,16 @@ uint16_t AudioEngine::preview(std::shared_ptr<Project> p, int16_t port, int16_t
|
||||||
deinitAudio();
|
deinitAudio();
|
||||||
project = p;
|
project = p;
|
||||||
|
|
||||||
|
// load audio settings
|
||||||
|
sampleRate = AudioConfig::previewSampleRate;
|
||||||
|
bufferMs = AudioConfig::previewBufferMs;
|
||||||
|
|
||||||
|
// reset state
|
||||||
queueValid = false;
|
queueValid = false;
|
||||||
queue.clear();
|
queue.clear();
|
||||||
buf.clear();
|
buf.clear();
|
||||||
project->rootGraph->reset();
|
project->rootGraph->reset();
|
||||||
|
|
||||||
sampleRate = AudioConfig::previewSampleRate;
|
|
||||||
bufferMs = AudioConfig::previewBufferMs;
|
|
||||||
initAudio();
|
initAudio();
|
||||||
for (auto& b : buffer) {
|
for (auto& b : buffer) {
|
||||||
b.clear();
|
b.clear();
|
||||||
|
@ -244,6 +249,10 @@ void AudioEngine::render(std::shared_ptr<Project> p, QString fileName) {
|
||||||
mode = Rendering;
|
mode = Rendering;
|
||||||
|
|
||||||
QMetaObject::invokeMethod(this, [this, fileName] {
|
QMetaObject::invokeMethod(this, [this, fileName] {
|
||||||
|
// load sample rate
|
||||||
|
sampleRate = AudioConfig::renderSampleRate;
|
||||||
|
|
||||||
|
// reset state
|
||||||
queueValid = false;
|
queueValid = false;
|
||||||
queue.clear();
|
queue.clear();
|
||||||
portLastNoteId.fill(0);
|
portLastNoteId.fill(0);
|
||||||
|
@ -259,7 +268,6 @@ void AudioEngine::render(std::shared_ptr<Project> p, QString fileName) {
|
||||||
tempo = project->tempo;
|
tempo = project->tempo;
|
||||||
tickAcc = 0;
|
tickAcc = 0;
|
||||||
|
|
||||||
sampleRate = AudioConfig::renderSampleRate;
|
|
||||||
initAudio(); // we actually need the period size. whoops.
|
initAudio(); // we actually need the period size. whoops.
|
||||||
|
|
||||||
QFileInfo fi(fileName);
|
QFileInfo fi(fileName);
|
||||||
|
|
|
@ -5,11 +5,16 @@ using namespace Xybrid;
|
||||||
|
|
||||||
#include <QDialogButtonBox>
|
#include <QDialogButtonBox>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QRegularExpression>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#include "fileops.h"
|
#include "fileops.h"
|
||||||
|
#include "config/audioconfig.h"
|
||||||
#include "config/uiconfig.h"
|
#include "config/uiconfig.h"
|
||||||
using namespace Xybrid::Config;
|
using namespace Xybrid::Config;
|
||||||
|
|
||||||
|
#include "util/strings.h"
|
||||||
|
|
||||||
SettingsDialog* SettingsDialog::instance = nullptr;
|
SettingsDialog* SettingsDialog::instance = nullptr;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -21,6 +26,36 @@ namespace {
|
||||||
v = o->isChecked();
|
v = o->isChecked();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const QRegularExpression numeric("[0-9.]+");
|
||||||
|
|
||||||
|
void bind(QComboBox* o, int& v, const QStringList& items) {
|
||||||
|
o->clear();
|
||||||
|
o->addItems(items);
|
||||||
|
int ld = 100000000;
|
||||||
|
QString cm;
|
||||||
|
for (auto& i : items) { // find closest match
|
||||||
|
auto q = numeric.match(i).captured().toInt();
|
||||||
|
int id = std::abs(q - v);
|
||||||
|
if (id < ld) {
|
||||||
|
ld = id;
|
||||||
|
cm = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
o->setCurrentText(cm);
|
||||||
|
bnd->push_back([o, &v] { // convert back to int
|
||||||
|
v = numeric.match(o->currentText()).captured().toInt();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void bind(QSpinBox* o, int& v, int min, int max, const QString& suffix = { }) {
|
||||||
|
o->setRange(min, max);
|
||||||
|
o->setValue(std::clamp(v, min, max));
|
||||||
|
o->setSuffix(suffix);
|
||||||
|
bnd->push_back([o, &v] {
|
||||||
|
v = o->value();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SettingsDialog::SettingsDialog(QWidget *parent) :
|
SettingsDialog::SettingsDialog(QWidget *parent) :
|
||||||
|
@ -33,6 +68,18 @@ SettingsDialog::SettingsDialog(QWidget *parent) :
|
||||||
instance = this;
|
instance = this;
|
||||||
bnd = &this->binds;
|
bnd = &this->binds;
|
||||||
|
|
||||||
|
// audio page
|
||||||
|
QStringList sampleRates = { qs("44100Hz"), qs("48000Hz"), qs("96000Hz") };
|
||||||
|
const constexpr int minBufMs = 5, maxBufMs = 250;
|
||||||
|
const QString ms = qs("ms");
|
||||||
|
|
||||||
|
bind(ui->playbackSampleRate, AudioConfig::playbackSampleRate, sampleRates);
|
||||||
|
bind(ui->playbackBufferMs, AudioConfig::playbackBufferMs, minBufMs, maxBufMs, ms);
|
||||||
|
bind(ui->previewSampleRate, AudioConfig::previewSampleRate, sampleRates);
|
||||||
|
bind(ui->previewBufferMs, AudioConfig::previewBufferMs, minBufMs, maxBufMs, ms);
|
||||||
|
bind(ui->renderSampleRate, AudioConfig::renderSampleRate, sampleRates);
|
||||||
|
|
||||||
|
// UI page
|
||||||
bind(ui->checkVerticalKnobs, UIConfig::verticalKnobs);
|
bind(ui->checkVerticalKnobs, UIConfig::verticalKnobs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>646</width>
|
<width>350</width>
|
||||||
<height>562</height>
|
<height>360</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
@ -34,13 +34,182 @@
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>0</number>
|
<number>0</number>
|
||||||
</property>
|
</property>
|
||||||
|
<widget class="QWidget" name="tabAudio">
|
||||||
|
<attribute name="title">
|
||||||
|
<string>Audio</string>
|
||||||
|
</attribute>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_3">
|
||||||
|
<item>
|
||||||
|
<widget class="QWidget" name="widget" native="true">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="text">
|
||||||
|
<string>Playback Sample Rate</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="playbackSampleRate"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QWidget" name="widget_2" native="true">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_2">
|
||||||
|
<property name="text">
|
||||||
|
<string>Playback Buffer Size</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSpinBox" name="playbackBufferMs"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QWidget" name="widget_3" native="true">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_4">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>Preview Sample Rate</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="previewSampleRate"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QWidget" name="widget_5" native="true">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_6">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_5">
|
||||||
|
<property name="text">
|
||||||
|
<string>Preview Buffer Size</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QSpinBox" name="previewBufferMs"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QWidget" name="widget_4" native="true">
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_5">
|
||||||
|
<property name="spacing">
|
||||||
|
<number>4</number>
|
||||||
|
</property>
|
||||||
|
<property name="leftMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="topMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="rightMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<property name="bottomMargin">
|
||||||
|
<number>0</number>
|
||||||
|
</property>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="label_4">
|
||||||
|
<property name="text">
|
||||||
|
<string>Rendering Sample Rate</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QComboBox" name="renderSampleRate"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="verticalSpacer_2">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
<widget class="QWidget" name="tabUI">
|
<widget class="QWidget" name="tabUI">
|
||||||
<property name="minimumSize">
|
|
||||||
<size>
|
|
||||||
<width>642</width>
|
|
||||||
<height>0</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
<string>UI</string>
|
<string>UI</string>
|
||||||
</attribute>
|
</attribute>
|
||||||
|
@ -113,7 +282,7 @@
|
||||||
<enum>Qt::Horizontal</enum>
|
<enum>Qt::Horizontal</enum>
|
||||||
</property>
|
</property>
|
||||||
<property name="standardButtons">
|
<property name="standardButtons">
|
||||||
<set>QDialogButtonBox::Apply|QDialogButtonBox::Cancel</set>
|
<set>QDialogButtonBox::Apply|QDialogButtonBox::Close</set>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
|
Loading…
Reference in New Issue