Commit e0b1b6a0 authored by Sandro Andrade's avatar Sandro Andrade

Refactor MidiPlayer and midisequencer state integration

parent ef90e36e
......@@ -43,7 +43,8 @@ MidiSequencer::MidiSequencer(QObject *parent) :
QObject(parent),
m_tick(0),
m_song(0),
m_eventSchedulingMode(FROM_ENGINE)
m_eventSchedulingMode(FROM_ENGINE),
m_state(StoppedState)
{
qmlRegisterType<MidiSequencer>("org.kde.minuet", 1, 0, "MidiSequencer");
// MidiClient configuration
......@@ -156,7 +157,6 @@ void MidiSequencer::openFile(const QString &fileName)
m_song = new Song();
m_eventSchedulingMode = FROM_ENGINE;
m_smfReader->readFromFile(fileName);
emit tempoChanged(6.0e7f / m_song->initialTempo());
m_song->sort();
m_midiSequencerOutputThread->setSong(m_song);
}
......@@ -201,7 +201,7 @@ MidiSequencer::EventSchedulingMode MidiSequencer::schedulingMode() const
void MidiSequencer::resetMidiPlayer()
{
setPlaybackLabel(QStringLiteral("00:00.00"));
emit stateChanged(MidiSequencer::StoppedState);
setState(StoppedState);
}
int MidiSequencer::pitch() const
......@@ -224,6 +224,11 @@ QString MidiSequencer::playbackLabel() const
return m_playbackLabel;
}
MidiSequencer::State MidiSequencer::state() const
{
return m_state;
}
void MidiSequencer::play()
{
if (m_song && !m_song->isEmpty() && !m_midiSequencerOutputThread->isRunning()) {
......@@ -232,7 +237,7 @@ void MidiSequencer::play()
m_midiSequencerOutputThread->setSong(m_song);
}
m_midiSequencerOutputThread->start();
emit stateChanged(MidiSequencer::PlayingState);
setState(PlayingState);
}
}
......@@ -242,7 +247,7 @@ void MidiSequencer::pause()
m_midiSequencerOutputThread->stop();
m_midiSequencerOutputThread->setPosition(m_queue->getStatus().getTickTime());
}
emit stateChanged(MidiSequencer::PausedState);
setState(PausedState);
}
void MidiSequencer::stop()
......@@ -251,15 +256,15 @@ void MidiSequencer::stop()
m_midiSequencerOutputThread->resetPosition();
emit allNotesOff();
setPlaybackLabel(QStringLiteral("00:00.00"));
emit stateChanged(MidiSequencer::StoppedState);
setState(StoppedState);
}
void MidiSequencer::setPitch(int pitch)
{
if (m_midiSequencerOutputThread->pitch() != pitch) {
m_midiSequencerOutputThread->setPitch(pitch);
emit pitchChanged();
emit allNotesOff();
emit pitchChanged(pitch);
}
}
......@@ -267,7 +272,7 @@ void MidiSequencer::setVolume(unsigned int volume)
{
if (m_midiSequencerOutputThread->volume() != volume) {
m_midiSequencerOutputThread->setVolume(volume);
emit volumeChanged(volume);
emit volumeChanged();
}
}
......@@ -280,17 +285,23 @@ void MidiSequencer::setTempo(unsigned int tempo)
queueTempo.setTempoFactor(tempoFactor);
m_queue->setTempo(queueTempo);
m_client->drainOutput();
emit tempoChanged(queueTempo.getRealBPM());
emit tempoChanged();
}
void MidiSequencer::setPlaybackLabel(QString playbackLabel)
{
if (m_playbackLabel != playbackLabel) {
m_playbackLabel = playbackLabel;
emit playbackLabelChanged(m_playbackLabel);
emit playbackLabelChanged();
}
}
void MidiSequencer::setState(State state)
{
m_state = state;
emit stateChanged();
}
void MidiSequencer::setSong(Song *song)
{
delete m_song;
......
......@@ -46,6 +46,8 @@ class MidiSequencer : public QObject
Q_PROPERTY(unsigned int volume READ volume WRITE setVolume NOTIFY volumeChanged)
Q_PROPERTY(unsigned int tempo READ tempo WRITE setTempo NOTIFY tempoChanged)
Q_PROPERTY(QString playbackLabel READ playbackLabel WRITE setPlaybackLabel NOTIFY playbackLabelChanged)
Q_ENUMS(State)
Q_PROPERTY(State state READ state NOTIFY stateChanged)
public:
explicit MidiSequencer(QObject *parent = 0);
......@@ -61,29 +63,29 @@ public:
PlayingState,
PausedState
};
Q_ENUMS(State)
void subscribeTo(const QString &portName);
void openFile(const QString &fileName);
void appendEvent(drumstick::SequencerEvent *ev, unsigned long tick);
QStringList availableOutputPorts() const;
EventSchedulingMode schedulingMode() const;
int pitch() const;
unsigned int volume() const;
unsigned int tempo() const;
QString playbackLabel() const;
State state() const;
Q_SIGNALS:
void noteOn(int chan, int pitch, int vel);
void noteOff(int chan, int pitch, int vel);
void allNotesOff();
void pitchChanged(int pitch);
void volumeChanged(unsigned int volume);
void tempoChanged(unsigned int tempo);
void playbackLabelChanged(QString playbackLabel);
void stateChanged(State state);
void pitchChanged();
void volumeChanged();
void tempoChanged();
void playbackLabelChanged();
void stateChanged();
public Q_SLOTS:
void play();
void pause();
......@@ -92,6 +94,7 @@ public Q_SLOTS:
void setVolume(unsigned int volume);
void setTempo(unsigned int tempo);
void setPlaybackLabel(QString playbackLabel);
void setState(State state);
void setSong(Song *song);
void clearSong();
......@@ -138,6 +141,7 @@ private:
EventSchedulingMode m_eventSchedulingMode;
QString m_currentSubscribedPort;
QString m_playbackLabel;
State m_state;
};
#endif // MIDISEQUENCER_H
......
......@@ -110,6 +110,12 @@ Item {
value: sequencer.playbackLabel
}
Binding {
target: midiPlayer
property: "sequencerState"
value: sequencer.state
}
Component.onCompleted: {
minuetMenu.breadcrumbPressed.connect(exerciseView.clearExerciseGrid)
minuetMenu.breadcrumbPressed.connect(rhythmAnswerView.resetAnswers)
......@@ -122,8 +128,6 @@ Item {
sequencer.noteOff.connect(pianoView.noteOff)
sequencer.allNotesOff.connect(pianoView.allNotesOff)
sequencer.stateChanged.connect(midiPlayer.stateChanged)
exerciseView.answerHoverEnter.connect(pianoView.noteMark)
exerciseView.answerHoverExit.connect(pianoView.noteUnmark)
exerciseView.answerClicked.connect(rhythmAnswerView.answerClicked)
......
......@@ -29,18 +29,12 @@ Rectangle {
property alias volume: volumeSlider.value
property alias tempo: tempoSlider.value
property alias playbackLabel: playbackLabelText.text
property int sequencerState
signal playActivated
signal pauseActivated
signal stopActivated
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 }
color: "black"
......@@ -92,40 +86,26 @@ Rectangle {
width: item1.width
horizontalAlignment: Text.AlignHCenter
font.pointSize: 24
text: "TESTE"
color: "#008000"
}
MultimediaButton {
id: item12
width: playbackLabelText.contentWidth / 2
anchors.horizontalCenterOffset: -30
anchors { top: playbackLabelText.bottom; horizontalCenter: playbackLabelText.horizontalCenter;}
state: "Play"
states: [
State {
name: "Play"
PropertyChanges {
target: item12;
text: i18n("Play")
onActivated: playActivated();
source: "../images/multimedia-play.png"
}
},
State {
name: "Pause"
PropertyChanges {
target: item12;
text: i18n("Pause")
onActivated: pauseActivated();
source: "../images/multimedia-pause.png"
}
}
]
anchors { top: playbackLabelText.bottom; horizontalCenter: playbackLabelText.horizontalCenter }
text: (sequencerState != MidiSequencer.PlayingState) ? i18n("Play"):i18n("Pause")
source: (sequencerState != MidiSequencer.PlayingState) ? "../images/multimedia-play.png":"../images/multimedia-pause.png"
onActivated: {
if (sequencerState == MidiSequencer.StoppedState || sequencerState == MidiSequencer.PausedState)
playActivated()
else
pauseActivated()
}
}
MultimediaButton {
width: playbackLabelText.contentWidth / 2
anchors.horizontalCenterOffset: +30
anchors { top: playbackLabelText.bottom; horizontalCenter: playbackLabelText.horizontalCenter;}
anchors { top: playbackLabelText.bottom; horizontalCenter: playbackLabelText.horizontalCenter }
source: "../images/multimedia-stop.png"
text: i18n("Stop")
onActivated: stopActivated()
......
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