Commit 8a0bd2fc authored by Sandro Andrade's avatar Sandro Andrade

Initial MinuetMenu refactoring

parent 73e88607
......@@ -39,10 +39,10 @@ class MINUETINTERFACES_EXPORT ICore : public QObject
{
Q_OBJECT
Q_PROPERTY(IPluginController * pluginController READ pluginController);
Q_PROPERTY(IPluginController * pluginController READ pluginController CONSTANT);
Q_PROPERTY(ISoundBackend * soundBackend READ soundBackend NOTIFY soundBackendChanged);
Q_PROPERTY(IExerciseController * exerciseController READ exerciseController);
Q_PROPERTY(IUiController * uiController READ uiController);
Q_PROPERTY(IExerciseController * exerciseController READ exerciseController CONSTANT);
Q_PROPERTY(IUiController * uiController READ uiController CONSTANT);
public:
virtual ~ICore() override;
......
......@@ -27,6 +27,7 @@
#include <QObject>
#include <QJsonArray>
#include <QJsonObject>
namespace Minuet
{
......@@ -37,7 +38,7 @@ class MINUETINTERFACES_EXPORT IExerciseController : public QObject
Q_PROPERTY(quint8 minRootNote MEMBER m_minRootNote)
Q_PROPERTY(quint8 maxRootNote MEMBER m_maxRootNote)
Q_PROPERTY(QJsonArray exercises READ exercises)
Q_PROPERTY(QJsonArray currentExercise MEMBER m_currentExercise)
Q_PROPERTY(QJsonObject currentExercise MEMBER m_currentExercise)
Q_PROPERTY(quint8 answerLength MEMBER m_answerLength)
Q_PROPERTY(QJsonArray selectedOptions MEMBER m_selectedOptions)
......@@ -54,7 +55,7 @@ protected:
quint8 m_minRootNote;
quint8 m_maxRootNote;
QJsonArray m_currentExercise;
QJsonObject m_currentExercise;
quint8 m_answerLength;
QJsonArray m_selectedOptions;
};
......
......@@ -75,7 +75,7 @@ public Q_SLOTS:
virtual void play() = 0;
virtual void pause() = 0;
virtual void stop() = 0;
Q_SIGNALS:
void pitchChanged(qint8 newPitch);
void volumeChanged(quint8 newVolume);
......
......@@ -73,9 +73,10 @@ void ExerciseController::randomlySelectOptions()
int minNote = INT_MAX;
int maxNote = INT_MIN;
for (quint8 i = 0; i < m_answerLength; ++i) {
quint8 chosenExercise = qrand() % m_currentExercise.size();
QJsonArray exerciseOptions = m_currentExercise[QStringLiteral("options")].toArray();
quint8 chosenExerciseOption = qrand() % exerciseOptions.size();
QString sequence = m_currentExercise[chosenExercise].toObject()[QStringLiteral("sequence")].toString();
QString sequence = exerciseOptions[chosenExerciseOption].toObject()[QStringLiteral("sequence")].toString();
foreach(const QString &additionalNote, sequence.split(' ')) {
int note = additionalNote.toInt();
if (note > maxNote) maxNote = note;
......@@ -85,10 +86,10 @@ void ExerciseController::randomlySelectOptions()
m_chosenRootNote = m_minRootNote + qrand() % (m_maxRootNote - m_minRootNote);
while (m_chosenRootNote + maxNote > 108 || m_chosenRootNote + minNote < 21);
QJsonObject jsonObject = m_currentExercise[chosenExercise].toObject();
QJsonObject jsonObject = exerciseOptions[chosenExerciseOption].toObject();
jsonObject["rootNote"] = QString::number(m_chosenRootNote);
m_currentExercise[chosenExercise] = jsonObject;
m_selectedOptions.append(m_currentExercise[chosenExercise]);
exerciseOptions[chosenExerciseOption] = jsonObject;
m_selectedOptions.append(exerciseOptions[chosenExerciseOption]);
}
}
......
......@@ -55,14 +55,14 @@ Item {
})
animation.start()
}
function itemChanged(model) {
// sequencer.allNotesOff()
function setCurrentExercise(currentExercise) {
clearExerciseGrid()
var length = model.length
var currentExerciseOptions = currentExercise["options"];
var length = currentExerciseOptions.length
answerGrid.columns = Math.min(6, length)
answerGrid.rows = Math.ceil(length/6)
for (var i = 0; i < length; ++i)
answerOption.createObject(answerGrid, {model: model[i], index: i, color: colors[i%24]})
answerOption.createObject(answerGrid, {model: currentExerciseOptions[i], index: i, color: colors[i%24]})
exerciseView.visible = true
exerciseView.state = "initial"
}
......
......@@ -44,11 +44,21 @@ Item {
width: menuBarWidth; height: parent.height - midiPlayer.height
anchors { left: parent.left; top: parent.top }
onCurrentExerciseChanged: { exerciseView.setCurrentExercise(currentExercise); rhythmAnswerView.resetAnswers() }
onBackPressed: { core.soundBackend.stop(); exerciseView.clearExerciseGrid() }
onUserMessageChanged: { exerciseView.changeUserMessage(message); mainItem.userMessageChanged(message) }
}
MidiPlayer {
id: midiPlayer
width: menuBarWidth
playbackLabel: core.soundBackend.playbackLabel
soundBackendState: core.soundBackend.state
onPlayActivated: core.soundBackend.play()
onPauseActivated: core.soundBackend.pause()
onStopActivated: core.soundBackend.stop()
}
Image {
id: background
......@@ -71,14 +81,28 @@ Item {
anchors { bottom: parent.bottom; bottomMargin: 14; horizontalCenter: parent.horizontalCenter }
visible: false
exerciseView: exerciseView
onAnswerCompleted: exerciseView.checkAnswers(answers)
}
ExerciseView {
id: exerciseView
width: background.width; height: minuetMenu.height + 20
anchors { top: background.top; horizontalCenter: background.horizontalCenter }
onAnswerHoverEnter: pianoView.noteMark(chan, pitch, vel, color)
onAnswerHoverExit: pianoView.noteUnmark(chan, pitch, vel)
onAnswerClicked: rhythmAnswerView.answerClicked(answerImageSource, color)
onStateChanged: mainItem.exerciseViewStateChanged()
onShowCorrectAnswer: rhythmAnswerView.showCorrectAnswer(chosenExercises, chosenColors)
onChosenExercisesChanged: rhythmAnswerView.fillCorrectAnswerGrid()
}
}
Binding {
target: core.exerciseController
property: "currentExercise"
value: minuetMenu.currentExercise
}
Binding {
target: core.soundBackend
property: "pitch"
......@@ -94,51 +118,10 @@ Item {
property: "tempo"
value: midiPlayer.tempo
}
Binding {
target: midiPlayer
property: "playbackLabel"
value: core.soundBackend.playbackLabel
}
Binding {
target: midiPlayer
property: "sequencerState"
value: core.soundBackend.state
}
Connections {
target: midiPlayer
onPlayActivated: core.soundBackend.play()
onPauseActivated: core.soundBackend.pause()
onStopActivated: core.soundBackend.stop()
}
// Connections {
// target: sequencer
// onNoteOn: pianoView.noteOn(chan, pitch, vel)
// onNoteOff: pianoView.noteOff(chan, pitch, vel)
// onAllNotesOff: pianoView.allNotesOff()
// }
Connections {
target: minuetMenu
onItemChanged: exerciseView.itemChanged(model)
onBreadcrumbPressed: exerciseView.clearExerciseGrid()
onUserMessageChanged: exerciseView.changeUserMessage(message)
}
Connections {
target: minuetMenu
onItemChanged: rhythmAnswerView.resetAnswers(model)
onBreadcrumbPressed: rhythmAnswerView.resetAnswers()
onUserMessageChanged: mainItem.userMessageChanged(message)
}
Connections {
target: exerciseView
onAnswerHoverEnter: pianoView.noteMark(chan, pitch, vel, color)
onAnswerHoverExit: pianoView.noteUnmark(chan, pitch, vel)
onAnswerClicked: rhythmAnswerView.answerClicked(answerImageSource, color)
onStateChanged: mainItem.exerciseViewStateChanged()
onShowCorrectAnswer: rhythmAnswerView.showCorrectAnswer(chosenExercises, chosenColors)
onChosenExercisesChanged: rhythmAnswerView.fillCorrectAnswerGrid()
}
Connections {
target: rhythmAnswerView
onAnswerCompleted: exerciseView.checkAnswers(answers)
}
}
......@@ -29,31 +29,20 @@ import org.kde.minuet 1.0
Item {
id: minuetMenu
property Item selectedMenuItem
property string message
readonly property alias currentExercise: stackView.currentExercise
signal breadcrumbPressed
signal itemChanged(var model)
signal backPressed
signal userMessageChanged(string message)
function itemClicked(delegateRect, index) {
var model = delegateRect.ListView.view.model[index].options
if (model != undefined) {
core.exerciseController.currentExercise = model
minuetMenu.itemChanged(model)
}
}
Button {
id: breadcrumb
width: (stackView.depth > 1) ? 24:0; height: parent.height
iconName: "go-previous"
onClicked: {
// sequencer.allNotesOff()
// sequencer.clearSong()
minuetMenu.breadcrumbPressed()
selectedMenuItem = null
backPressed()
stackView.currentExerciseMenuItem = null
stackView.pop()
userMessageChanged("exercise")
if (stackView.depth == 1)
......@@ -63,6 +52,9 @@ Item {
StackView {
id: stackView
property var currentExercise
property Item currentExerciseMenuItem
width: parent.width - breadcrumb.width; height: parent.height
anchors.left: breadcrumb.right
clip: true
......@@ -83,10 +75,10 @@ Item {
message = userMessage
var children = delegateRect.ListView.view.model[index].children
if (!children) {
if (selectedMenuItem != undefined) selectedMenuItem.checked = false
if (stackView.currentExerciseMenuItem != undefined) stackView.currentExerciseMenuItem.checked = false
userMessageChanged(message)
itemClicked(delegateRect, index)
selectedMenuItem = delegateRect
stackView.currentExercise = delegateRect.ListView.view.model[index]
stackView.currentExerciseMenuItem = delegateRect
}
else {
stackView.push(categoryMenu.createObject(stackView, {model: children}))
......
......@@ -26,11 +26,11 @@ import org.kde.plasma.core 2.0 as PlasmaCore
import org.kde.minuet 1.0
Rectangle {
property alias pitch: pitchSlider.value
property alias volume: volumeSlider.value
property alias tempo: tempoSlider.value
readonly property alias pitch: pitchSlider.value
readonly property alias volume: volumeSlider.value
readonly property alias tempo: tempoSlider.value
property alias playbackLabel: playbackLabelText.text
property int sequencerState
property int soundBackendState
signal playActivated
signal pauseActivated
......@@ -90,10 +90,10 @@ Rectangle {
width: playbackLabelText.contentWidth / 2
anchors.horizontalCenterOffset: -30
anchors { top: playbackLabelText.bottom; horizontalCenter: playbackLabelText.horizontalCenter }
text: (sequencerState != ISoundBackend.PlayingState) ? i18n("Play"):i18n("Pause")
source: (sequencerState != ISoundBackend.PlayingState) ? "../images/multimedia-play.png":"../images/multimedia-pause.png"
text: (soundBackendState != ISoundBackend.PlayingState) ? i18n("Play"):i18n("Pause")
source: (soundBackendState != ISoundBackend.PlayingState) ? "../images/multimedia-play.png":"../images/multimedia-pause.png"
onActivated: {
if (sequencerState == ISoundBackend.StoppedState || sequencerState == ISoundBackend.PausedState)
if (soundBackendState == ISoundBackend.StoppedState || soundBackendState == ISoundBackend.PausedState)
playActivated()
else
pauseActivated()
......
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