Commit 3f7fbacf authored by Sandro Andrade's avatar Sandro Andrade

Fix some bugs in drumsticksoundbackend

parent 19dc2478
......@@ -38,8 +38,10 @@ class MINUETINTERFACES_EXPORT ISoundBackend : public IPlugin
Q_PROPERTY(int pitch MEMBER m_pitch NOTIFY pitchChanged)
Q_PROPERTY(quint8 volume MEMBER m_volume NOTIFY volumeChanged)
Q_PROPERTY(quint8 tempo MEMBER m_tempo NOTIFY tempoChanged)
Q_PROPERTY(quint8 tempo MEMBER m_tempo WRITE setTempo NOTIFY tempoChanged)
Q_PROPERTY(QString playbackLabel READ playbackLabel NOTIFY playbackLabelChanged)
Q_ENUMS(PlayMode)
Q_PROPERTY(PlayMode playMode MEMBER m_playMode NOTIFY playModeChanged)
Q_ENUMS(State)
Q_PROPERTY(State state READ state NOTIFY stateChanged)
......@@ -48,6 +50,12 @@ public:
QString playbackLabel() const;
enum PlayMode {
ScalePlayMode = 0,
ChordPlayMode,
RhythmPlayMode
};
enum State {
StoppedState = 0,
PlayingState,
......@@ -57,7 +65,9 @@ public:
ISoundBackend::State state() const;
public Q_SLOTS:
virtual void prepareFromExerciseOptions(QJsonArray selectedOptions, const QString &playMode) = 0;
virtual void setTempo (quint8 tempo) = 0;
virtual void prepareFromExerciseOptions(QJsonArray selectedOptions) = 0;
virtual void prepareFromMidiFile(const QString &fileName) = 0;
virtual void play() = 0;
......@@ -70,6 +80,7 @@ Q_SIGNALS:
void tempoChanged(quint8 newTempo);
void playbackLabelChanged(QString newPlaybackLabel);
void stateChanged(State newState);
void playModeChanged(PlayMode newPlayMode);
protected:
explicit ISoundBackend(QObject *parent = 0);
......@@ -81,6 +92,7 @@ protected:
quint8 m_tempo;
QString m_playbackLabel;
State m_state;
PlayMode m_playMode;
};
}
......
......@@ -34,7 +34,7 @@
DrumstickSoundBackend::DrumstickSoundBackend(QObject *parent)
: Minuet::ISoundBackend(parent),
m_song(0)
m_song(0)
{
// MidiClient configuration
m_client = new drumstick::MidiClient(this);
......@@ -60,7 +60,7 @@ DrumstickSoundBackend::DrumstickSoundBackend(QObject *parent)
m_client->setRealTimeInput(false);
m_client->startSequencerInput();
// Output port configuration
// Output port configuration (to TiMidity)
m_outputPort = new drumstick::MidiPort(this);
m_outputPort->attach(m_client);
m_outputPort->setPortName(QStringLiteral("Minuet Sequencer Output Port"));
......@@ -68,7 +68,7 @@ DrumstickSoundBackend::DrumstickSoundBackend(QObject *parent)
m_outputPort->setPortType(SND_SEQ_PORT_TYPE_APPLICATION | SND_SEQ_PORT_TYPE_MIDI_GENERIC);
m_outputPortId = m_outputPort->getPortId();
// Input port configuration
// Input port configuration (from ALSA)
m_inputPort = new drumstick::MidiPort(this);
m_inputPort->attach(m_client);
m_inputPort->setPortName(QStringLiteral("Minuet Sequencer Input Port"));
......@@ -88,6 +88,15 @@ DrumstickSoundBackend::DrumstickSoundBackend(QObject *parent)
setState(StoppedState);
});
// Subscribe to Minuet's virtual piano
try {
m_outputPort->subscribeTo(QStringLiteral("MinuetSequencer:1"));
} catch (const drumstick::SequencerError &err) {
qCDebug(MINUET) << "Subscribe error";
throw err;
}
setPlaybackLabel(QStringLiteral("00:00.00"));
startTimidity();
m_outputPort->subscribeTo("TiMidity:0");
}
......@@ -99,9 +108,29 @@ DrumstickSoundBackend::~DrumstickSoundBackend()
m_inputPort->detach();
m_client->close();
delete m_midiSequencerOutputThread;
m_timidityProcess.kill();
qCDebug(MINUET) << "Stoping TiMidity++!";
if (!m_timidityProcess.waitForFinished(-1))
qCDebug(MINUET) << "Error when stoping TiMidity++:" << m_timidityProcess.errorString();
else
qCDebug(MINUET) << "TiMidity++ stoped!";
}
void DrumstickSoundBackend::setTempo (quint8 tempo)
{
float tempoFactor = (tempo*tempo + 100.0*tempo + 20000.0) / 40000.0;
m_midiSequencerOutputThread->setTempoFactor(tempoFactor);
drumstick::QueueTempo queueTempo = m_queue->getTempo();
queueTempo.setTempoFactor(tempoFactor);
m_queue->setTempo(queueTempo);
m_client->drainOutput();
m_tempo = tempo;
emit tempoChanged(m_tempo);
}
void DrumstickSoundBackend::prepareFromExerciseOptions(QJsonArray selectedOptions, const QString &playMode)
void DrumstickSoundBackend::prepareFromExerciseOptions(QJsonArray selectedOptions)
{
Song *song = new Song;
song->setHeader(0, 1, 60);
......@@ -113,7 +142,7 @@ void DrumstickSoundBackend::prepareFromExerciseOptions(QJsonArray selectedOption
appendEvent(new drumstick::TempoEvent(m_queueId, 600000), 0);
unsigned int barStart = 0;
if (playMode == "rhythm") {
if (m_playMode == RhythmPlayMode) {
appendEvent(new drumstick::NoteOnEvent(9, 80, 120), 0);
appendEvent(new drumstick::NoteOnEvent(9, 80, 120), 60);
appendEvent(new drumstick::NoteOnEvent(9, 80, 120), 120);
......@@ -125,18 +154,18 @@ void DrumstickSoundBackend::prepareFromExerciseOptions(QJsonArray selectedOption
QString sequence = selectedOptions[i].toObject()[QStringLiteral("sequence")].toString();
unsigned int chosenRootNote = selectedOptions[i].toObject()[QStringLiteral("rootNote")].toString().toInt();
if (playMode != "rhythm") {
if (m_playMode != RhythmPlayMode) {
appendEvent(new drumstick::NoteOnEvent(1, chosenRootNote, 120), barStart);
appendEvent(new drumstick::NoteOnEvent(1, chosenRootNote, 120), barStart + 60);
appendEvent(new drumstick::NoteOffEvent(1, chosenRootNote, 120), barStart + 60);
unsigned int j = 1;
drumstick::SequencerEvent *ev;
foreach(const QString &additionalNote, sequence.split(' ')) {
appendEvent(ev = new drumstick::NoteOnEvent(1, chosenRootNote + additionalNote.toInt(), 120),
(playMode == "scale") ? barStart+60*j:barStart);
(m_playMode == ScalePlayMode) ? barStart+60*j:barStart);
ev->setTag(0);
appendEvent(ev = new drumstick::NoteOffEvent(1, chosenRootNote + additionalNote.toInt(), 120),
(playMode == "scale") ? barStart+60*(j+1):barStart+60);
(m_playMode == ScalePlayMode) ? barStart+60*(j+1):barStart+60);
ev->setTag(0);
++j;
}
......@@ -155,7 +184,7 @@ void DrumstickSoundBackend::prepareFromExerciseOptions(QJsonArray selectedOption
}
}
}
if (playMode == "rhythm")
if (m_playMode == RhythmPlayMode)
appendEvent(new drumstick::NoteOnEvent(9, 80, 120), barStart);
}
......
......@@ -55,7 +55,9 @@ public:
virtual ~DrumstickSoundBackend() override;
public Q_SLOTS:
virtual void prepareFromExerciseOptions(QJsonArray selectedOptions, const QString &playMode) override;
virtual void setTempo (quint8 tempo);
virtual void prepareFromExerciseOptions(QJsonArray selectedOptions) override;
virtual void prepareFromMidiFile(const QString &fileName) override;
virtual void play() override;
......
......@@ -31,10 +31,14 @@ FluidSynthSoundBackend::~FluidSynthSoundBackend()
{
}
void FluidSynthSoundBackend::prepareFromExerciseOptions(QJsonArray selectedOptions, const QString &playMode)
void FluidSynthSoundBackend::setTempo (quint8 tempo)
{
Q_UNUSED(tempo);
}
void FluidSynthSoundBackend::prepareFromExerciseOptions(QJsonArray selectedOptions)
{
Q_UNUSED(selectedOptions)
Q_UNUSED(playMode)
}
void FluidSynthSoundBackend::prepareFromMidiFile(const QString &fileName)
......
......@@ -38,7 +38,9 @@ public:
virtual ~FluidSynthSoundBackend() override;
public Q_SLOTS:
virtual void prepareFromExerciseOptions(QJsonArray selectedOptions, const QString &playMode) override;
virtual void setTempo (quint8 tempo);
virtual void prepareFromExerciseOptions(QJsonArray selectedOptions) override;
virtual void prepareFromMidiFile(const QString &fileName) override;
virtual void play() override;
......
......@@ -51,6 +51,8 @@ ExerciseController::~ExerciseController()
bool ExerciseController::initialize(Core *core)
{
Q_UNUSED(core)
bool definitionsMerge = mergeJsonFiles("definitions", m_definitions);
bool exercisesMerge = mergeJsonFiles("exercises", m_exercises, true, "name", "children");
......
......@@ -24,6 +24,8 @@ import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Controls.Styles 1.1
import org.kde.minuet 1.0
Item {
id: minuetMenu
......@@ -95,11 +97,11 @@ Item {
}
var playMode = delegateRect.ListView.view.model[index].playMode
if (playMode != undefined) {
// if (playMode == "scale") sequencer.setPlayMode(0) // ScalePlayMode
// if (playMode == "chord") sequencer.setPlayMode(1) // ChordPlayMode
if (playMode == "scale") core.soundBackend.playMode = ISoundBackend.ScalePlayMode
if (playMode == "chord") core.soundBackend.playMode = ISoundBackend.ChordPlayMode
core.exerciseController.answerLength = 1
if (playMode == "rhythm") {
core.exerciseController.setPlayMode(2) // RhythmPlayMode
core.soundBackend.playMode = ISoundBackend.RhythmPlayMode
core.exerciseController.answerLength = 4
}
}
......
......@@ -22,6 +22,7 @@
import QtQuick 2.4
import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.minuet 1.0
Rectangle {
......@@ -92,7 +93,7 @@ Rectangle {
text: (sequencerState != ISoundBackend.PlayingState) ? i18n("Play"):i18n("Pause")
source: (sequencerState != ISoundBackend.PlayingState) ? "../images/multimedia-play.png":"../images/multimedia-pause.png"
onActivated: {
if (sequencerState == ISoundBackend.StoppedState || sequencerState == MidiSequencer.PausedState)
if (sequencerState == ISoundBackend.StoppedState || sequencerState == ISoundBackend.PausedState)
playActivated()
else
pauseActivated()
......
......@@ -39,6 +39,8 @@ UiController::~UiController()
bool UiController::initialize(Core *core)
{
Q_UNUSED(core);
m_mainWindow->show();
return true;
}
......
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