Commit 8897c363 authored by Sandro Andrade's avatar Sandro Andrade

Refactor to use QML Connections rather than JavaScript connections

parent 81d1b83c
...@@ -21,6 +21,7 @@ ...@@ -21,6 +21,7 @@
****************************************************************************/ ****************************************************************************/
import QtQuick 2.4 import QtQuick 2.4
import "pianoview" import "pianoview"
import "midiplayer" import "midiplayer"
...@@ -33,8 +34,8 @@ Item { ...@@ -33,8 +34,8 @@ Item {
pianoView.visible = (message != "the rhythm" && message != "exercise") pianoView.visible = (message != "the rhythm" && message != "exercise")
rhythmAnswerView.visible = (message == "the rhythm") rhythmAnswerView.visible = (message == "the rhythm")
} }
function exerciseViewStateChanged(state) { function exerciseViewStateChanged() {
if (state == "waitingForAnswer") if (exerciseView.state == "waitingForAnswer")
rhythmAnswerView.resetAnswers() rhythmAnswerView.resetAnswers()
} }
...@@ -78,12 +79,6 @@ Item { ...@@ -78,12 +79,6 @@ Item {
anchors { top: background.top; horizontalCenter: background.horizontalCenter } anchors { top: background.top; horizontalCenter: background.horizontalCenter }
} }
} }
Connections {
target: midiPlayer
onPlayActivated: sequencer.play()
onPauseActivated: sequencer.pause()
onStopActivated: sequencer.stop()
}
Binding { Binding {
target: sequencer target: sequencer
property: "pitch" property: "pitch"
...@@ -109,26 +104,41 @@ Item { ...@@ -109,26 +104,41 @@ Item {
property: "sequencerState" property: "sequencerState"
value: sequencer.state value: sequencer.state
} }
Connections {
Component.onCompleted: { target: midiPlayer
minuetMenu.breadcrumbPressed.connect(exerciseView.clearExerciseGrid) onPlayActivated: sequencer.play()
minuetMenu.breadcrumbPressed.connect(rhythmAnswerView.resetAnswers) onPauseActivated: sequencer.pause()
minuetMenu.itemChanged.connect(exerciseView.itemChanged) onStopActivated: sequencer.stop()
minuetMenu.userMessageChanged.connect(exerciseView.changeUserMessage) }
minuetMenu.userMessageChanged.connect(mainItem.userMessageChanged) Connections {
minuetMenu.itemChanged.connect(rhythmAnswerView.resetAnswers) target: sequencer
onNoteOn: pianoView.noteOn(chan, pitch, vel)
sequencer.noteOn.connect(pianoView.noteOn) onNoteOff: pianoView.noteOff(chan, pitch, vel)
sequencer.noteOff.connect(pianoView.noteOff) onAllNotesOff: pianoView.allNotesOff()
sequencer.allNotesOff.connect(pianoView.allNotesOff) }
Connections {
exerciseView.answerHoverEnter.connect(pianoView.noteMark) target: minuetMenu
exerciseView.answerHoverExit.connect(pianoView.noteUnmark) onItemChanged: exerciseView.itemChanged(model)
exerciseView.answerClicked.connect(rhythmAnswerView.answerClicked) onBreadcrumbPressed: exerciseView.clearExerciseGrid()
exerciseView.onStateChanged.connect(mainItem.exerciseViewStateChanged) onUserMessageChanged: exerciseView.changeUserMessage(message)
exerciseView.showCorrectAnswer.connect(rhythmAnswerView.showCorrectAnswer) }
exerciseView.onChosenExercisesChanged.connect(rhythmAnswerView.fillCorrectAnswerGrid) Connections {
target: minuetMenu
rhythmAnswerView.answerCompleted.connect(exerciseView.checkAnswers) 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)
} }
} }
...@@ -63,10 +63,10 @@ Column { ...@@ -63,10 +63,10 @@ Column {
colors = ["#ffffff", "#ffffff", "#ffffff", "#ffffff"] colors = ["#ffffff", "#ffffff", "#ffffff", "#ffffff"]
correctColors = ["#ffffff", "#ffffff", "#ffffff", "#ffffff"] correctColors = ["#ffffff", "#ffffff", "#ffffff", "#ffffff"]
} }
function showCorrectAnswer(chosenExercise, chosenColors) { function showCorrectAnswer(chosenExercises, chosenColors) {
var tempAnswers = answers var tempAnswers = answers
for (var i = 0; i < 4; ++i) for (var i = 0; i < 4; ++i)
tempAnswers[i] = "exercise-images/" + chosenExercise[i] + ".png" tempAnswers[i] = "exercise-images/" + chosenExercises[i] + ".png"
answers = tempAnswers answers = tempAnswers
colors = chosenColors colors = chosenColors
currentAnswer = 0 currentAnswer = 0
......
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