toolbar works more sensibly now; actual play button

portability/boost
zetaPRIME 2019-06-20 20:16:48 -04:00
parent 5fc2c4b750
commit d2a39a9be6
4 changed files with 118 additions and 20 deletions

View File

@ -111,8 +111,8 @@ void AudioEngine::deinitAudio() {
}
}
void AudioEngine::play(std::shared_ptr<Project> p) {
QMetaObject::invokeMethod(this, [this, p] {
void AudioEngine::play(std::shared_ptr<Project> p, int fromPos) {
QMetaObject::invokeMethod(this, [this, p, fromPos] {
if (!p) return; // nope
project = p;
@ -128,7 +128,9 @@ void AudioEngine::play(std::shared_ptr<Project> p) {
b.reserve(static_cast<size_t>(sampleRate/4));
}
seqPos = -1;
seqPos = fromPos;
curRow = -2;
curTick = -2;
tempo = project->tempo;
tickAcc = 0;

View File

@ -99,7 +99,7 @@ namespace Xybrid::Audio {
static void init();
inline constexpr PlaybackMode playbackMode() const { return mode; }
inline constexpr const std::shared_ptr<Data::Project>& playingProject() const { return project; }
void play(std::shared_ptr<Data::Project>);
void play(std::shared_ptr<Data::Project>, int fromPos = -1);
void stop();
uint16_t preview(std::shared_ptr<Data::Project>, int16_t port, int16_t note, uint16_t nId = 0);
inline uint8_t previewPort() const { return previewPort_; }

View File

@ -88,12 +88,6 @@ MainWindow::MainWindow(QWidget *parent) :
redoAction->setShortcuts(QKeySequence::Redo);
ui->menuEdit->addAction(redoAction);
auto* t = ui->tabWidget;
t->setCurrentWidget(ui->pattern); // set default regardless of what was edited last in the designer :|
t->setCornerWidget(ui->menuBar);
t->setCornerWidget(ui->logo, Qt::TopLeftCorner);
//ui->menuBar->setStyleSheet("QMenuBar { background: transparent; vertical-align: center; } QMenuBar::item { } QMenuBar::item:!pressed { background: transparent; }");
// prevent right pane of pattern view from being collapsed
ui->patternViewSplitter->setCollapsible(1, false);
connect(ui->patternViewSplitter, &QSplitter::splitterMoved, this, [this](int, int) {
@ -101,6 +95,30 @@ MainWindow::MainWindow(QWidget *parent) :
ui->patternEditor->updateHeader();
});
{ /* Set up toolbar */ } {
auto* t = ui->tabWidget;
t->setCurrentWidget(ui->pattern); // set default regardless of what was edited last in the designer :|
t->setCornerWidget(ui->logo, Qt::TopLeftCorner);
auto* tb = ui->toolBar;
t->setCornerWidget(tb);
tb->layout()->addWidget(ui->menuBar);
ui->playButton->setIcon(ui->playButton->style()->standardIcon(QStyle::SP_MediaPlay));
// play/stop
auto play = new QAction(this);
play->setShortcuts({ QKeySequence("Ctrl+P"), QKeySequence("Ctrl+Shift+P") });
ui->playButton->setDefaultAction(play);
connect(play, &QAction::triggered, this, [this] {
if (audioEngine->playbackMode() == AudioEngine::Playing && audioEngine->playingProject() == project) audioEngine->stop();
else {
bool shift = QGuiApplication::keyboardModifiers().testFlag(Qt::KeyboardModifier::ShiftModifier);
if (shift) audioEngine->play(project, ui->patternSequencer->currentIndex().column());
else audioEngine->play(project);
}
});
//ui->menuBar->setStyleSheet("QMenuBar { background: transparent; vertical-align: center; } QMenuBar::item { } QMenuBar::item:!pressed { background: transparent; }");
}
{ /* Set up pattern list */ } {
// model
ui->patternList->setModel(new PatternListModel(ui->patternList, this));
@ -243,12 +261,6 @@ MainWindow::MainWindow(QWidget *parent) :
ui->patternSequencer->setCurrentIndex(i.siblingAtColumn((count + i.column() + 1) % count));
});
// TEMP - play/stop
connect(new QShortcut(QKeySequence("Ctrl+P"), this), &QShortcut::activated, this, [this] {
if (audioEngine->playbackMode() == AudioEngine::Playing) audioEngine->stop();
else audioEngine->play(project);
});
/* tmp test
connect(new QShortcut(QKeySequence("Ctrl+F1"), ui->patchboard), &QShortcut::activated, this, [this] {
auto inp = QInputDialog::getText(this, "yes", "yes");
@ -352,6 +364,10 @@ MainWindow::MainWindow(QWidget *parent) :
bool locked = project->editingLocked();
undoAction->setEnabled(!locked);
redoAction->setEnabled(!locked);
bool playingThis = audioEngine->playbackMode() == AudioEngine::Playing && audioEngine->playingProject() == project;
if (playingThis) ui->playButton->setIcon(ui->playButton->style()->standardIcon(QStyle::SP_MediaStop));
else ui->playButton->setIcon(ui->playButton->style()->standardIcon(QStyle::SP_MediaPlay));
});
selectSampleForEditing(nullptr); // init blank

View File

@ -33,7 +33,7 @@
<enum>Qt::NoFocus</enum>
</property>
<property name="currentIndex">
<number>0</number>
<number>3</number>
</property>
<property name="documentMode">
<bool>true</bool>
@ -723,6 +723,80 @@
<pixmap resource="res/resources.qrc">:/img/xybrid-logo-tiny.png</pixmap>
</property>
</widget>
<widget class="QWidget" name="toolBar" native="true">
<property name="geometry">
<rect>
<x>80</x>
<y>150</y>
<width>731</width>
<height>28</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<layout class="QHBoxLayout" name="horizontalLayout_7">
<property name="spacing">
<number>2</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>
<spacer name="toolBarSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>0</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QToolButton" name="playButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="minimumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="maximumSize">
<size>
<width>24</width>
<height>24</height>
</size>
</property>
<property name="shortcut">
<string>Ctrl+P, Ctrl+Shift+P</string>
</property>
<property name="autoRaise">
<bool>true</bool>
</property>
</widget>
</item>
</layout>
</widget>
</widget>
</widget>
</item>
@ -734,7 +808,7 @@
<x>0</x>
<y>0</y>
<width>920</width>
<height>21</height>
<height>28</height>
</rect>
</property>
<property name="sizePolicy">
@ -743,7 +817,13 @@
<verstretch>255</verstretch>
</sizepolicy>
</property>
<widget class="QMenu" name="menua_menu_item">
<property name="minimumSize">
<size>
<width>0</width>
<height>28</height>
</size>
</property>
<widget class="QMenu" name="menuFile">
<property name="title">
<string>&amp;File</string>
</property>
@ -765,7 +845,7 @@
<string>He&amp;lp</string>
</property>
</widget>
<addaction name="menua_menu_item"/>
<addaction name="menuFile"/>
<addaction name="menuEdit"/>
<addaction name="menuHelp"/>
</widget>