Commit cdc66fce authored by Kushagra Surana's avatar Kushagra Surana Committed by Sandro Andrade

Merge the play and pause button

Instead of having two multimedia buttons, we can have the functionality with only one button with two states.
One state for play and other for pause.
Hence whenever they are called, a signal is sent to slot in MidiPlayer.qml.

Reviewers: sandroandrade

Subscribers: itsback

Tags: #minuet

Differential Revision: https://phabricator.kde.org/D1106
parent 394053f2
......@@ -32,6 +32,8 @@
#include <QLoggingCategory>
#include <QApplication>
#include <QtQml>
Q_DECLARE_LOGGING_CATEGORY(MINUET)
#include <drumstick/qsmf.h>
......@@ -43,6 +45,7 @@ MidiSequencer::MidiSequencer(QObject *parent) :
m_song(0),
m_eventSchedulingMode(FROM_ENGINE)
{
qmlRegisterType<MidiSequencer>("org.kde.minuet", 1, 0, "MidiSequencer");
// MidiClient configuration
m_client = new drumstick::MidiClient(this);
try {
......@@ -108,7 +111,7 @@ MidiSequencer::MidiSequencer(QObject *parent) :
// OutputThread
m_midiSequencerOutputThread = new MidiSequencerOutputThread(m_client, m_outputPortId);
connect(m_midiSequencerOutputThread, &MidiSequencerOutputThread::stopped, this, &MidiSequencer::outputThreadStopped);
connect(m_midiSequencerOutputThread, &MidiSequencerOutputThread::finished, this, &MidiSequencer::resetTimer);
connect(m_midiSequencerOutputThread, &MidiSequencerOutputThread::finished, this, &MidiSequencer::resetMidiPlayer);
// Subscribe to Minuet's virtual piano
try {
......@@ -194,9 +197,10 @@ MidiSequencer::EventSchedulingMode MidiSequencer::schedulingMode() const
return m_eventSchedulingMode;
}
void MidiSequencer::resetTimer()
void MidiSequencer::resetMidiPlayer()
{
emit timeLabelChanged(QStringLiteral("00:00.00"));
emit stateChanged(MidiSequencer::StoppedState);
}
void MidiSequencer::play()
......@@ -207,6 +211,7 @@ void MidiSequencer::play()
m_midiSequencerOutputThread->setSong(m_song);
}
m_midiSequencerOutputThread->start();
emit stateChanged(MidiSequencer::PlayingState);
}
}
......@@ -216,6 +221,7 @@ void MidiSequencer::pause()
m_midiSequencerOutputThread->stop();
m_midiSequencerOutputThread->setPosition(m_queue->getStatus().getTickTime());
}
emit stateChanged(MidiSequencer::PausedState);
}
void MidiSequencer::stop()
......@@ -224,6 +230,7 @@ void MidiSequencer::stop()
m_midiSequencerOutputThread->resetPosition();
emit allNotesOff();
emit timeLabelChanged(QStringLiteral("00:00.00"));
emit stateChanged(MidiSequencer::StoppedState);
}
void MidiSequencer::setVolumeFactor(unsigned int vol)
......
......@@ -51,6 +51,12 @@ public:
EXPLICIT,
DAMAGED
};
enum State {
StoppedState = 0,
PlayingState,
PausedState
};
Q_ENUMS(State)
void subscribeTo(const QString &portName);
void openFile(const QString &fileName);
......@@ -66,6 +72,7 @@ Q_SIGNALS:
void volumeChanged(unsigned int vol);
void tempoChanged(unsigned int vol);
void pitchChanged(int vol);
void stateChanged(State state);
public Q_SLOTS:
void play();
......@@ -98,7 +105,7 @@ private Q_SLOTS:
void eventReceived(drumstick::SequencerEvent *ev);
void outputThreadStopped();
void resetTimer();
void resetMidiPlayer();
private:
void appendEvent(drumstick::SequencerEvent *ev);
......
......@@ -95,6 +95,7 @@ Item {
sequencer.volumeChanged.connect(midiPlayer.volumeChanged)
sequencer.tempoChanged.connect(midiPlayer.tempoChanged)
sequencer.pitchChanged.connect(midiPlayer.pitchChanged)
sequencer.stateChanged.connect(midiPlayer.stateChanged)
exerciseView.answerHoverEnter.connect(pianoView.noteMark)
exerciseView.answerHoverExit.connect(pianoView.noteUnmark)
......
......@@ -22,12 +22,19 @@
import QtQuick 2.4
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.minuet 1.0
Rectangle {
function timeLabelChanged(timeLabel) { playbackTime.text = timeLabel }
function volumeChanged(value) { volumeLabel.text = i18n("Volume: %1\%").arg(value) }
function tempoChanged(value) { tempoLabel.text = i18n("Tempo: %1 bpm").arg(value) }
function pitchChanged(value) { pitchLabel.text = i18n("Pitch: %1").arg(value) }
function stateChanged(state) {
if (state == MidiSequencer.PlayingState)
item12.state = "Pause"
else
item12.state = "Play"
}
height: childrenRect.height + 15
anchors { left: parent.left; bottom: parent.bottom }
......@@ -85,20 +92,33 @@ Rectangle {
}
MultimediaButton {
id: item12
anchors { top: playbackTime.bottom; horizontalCenter: playbackTime.horizontalCenter }
source: "../images/multimedia-pause.png"
text: i18n("Pause")
onActivated: sequencer.pause()
}
MultimediaButton {
anchors { top: playbackTime.bottom; right: item12.left; rightMargin: -2 }
source: "../images/multimedia-play.png"
text: i18n("Play")
onActivated: sequencer.play()
anchors.horizontalCenterOffset: -30
anchors { top: playbackTime.bottom; horizontalCenter: playbackTime.horizontalCenter;}
state: "Play"
states: [
State {
name: "Play"
PropertyChanges {
target: item12;
text: i18n("Play")
onActivated: sequencer.play();
source: "../images/multimedia-play.png"
}
},
State {
name: "Pause"
PropertyChanges {
target: item12;
text: i18n("Pause")
onActivated: sequencer.pause();
source: "../images/multimedia-pause.png"
}
}
]
}
MultimediaButton {
anchors { top: playbackTime.bottom; left: item12.right; leftMargin: -2 }
anchors.horizontalCenterOffset: +30
anchors { top: playbackTime.bottom; horizontalCenter: playbackTime.horizontalCenter;}
source: "../images/multimedia-stop.png"
text: i18n("Stop")
onActivated: sequencer.stop()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment