[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [gcompris/gsoc_aman_piano_activities] src/activities: 1. Added keyboard control for note_names.
From:       Aman Kumar Gupta <null () kde ! org>
Date:       2018-08-01 1:57:16
Message-ID: E1fkgO4-0005y0-PQ () code ! kde ! org
[Download RAW message or body]

Git commit 7d819e1a2f593c9a6b96fb2cccc308d378748b09 by Aman Kumar Gupta.
Committed on 01/08/2018 at 01:52.
Pushed by amankumargupta into branch 'gsoc_aman_piano_activities'.

1. Added keyboard control for note_names.
2. Display multiple notes at the same time in note_names.
3. Added advanced timer for pause/resume feature.
4. Changed dataset.qml to dataset_01.qnl in note_names.
5. Made quarter note as the default note in piano_composition.

A  +67   -0    src/activities/note_names/AdvancedTimer.qml     [License: GPL (v3+)]
M  +79   -7    src/activities/note_names/NoteNames.qml
M  +17   -8    src/activities/note_names/note_names.js
R  +4    -27   src/activities/note_names/resource/dataset_01.json [from: \
src/activities/note_names/resource/dataset.qml - 061% similarity] M  +12   -4    \
src/activities/piano_composition/MultipleStaff.qml M  +1    -0    \
src/activities/piano_composition/OptionsRow.qml M  +2    -2    \
src/activities/piano_composition/Piano_composition.qml M  +2    -0    \
src/activities/piano_composition/piano_composition.js

https://commits.kde.org/gcompris/7d819e1a2f593c9a6b96fb2cccc308d378748b09

diff --git a/src/activities/note_names/AdvancedTimer.qml \
b/src/activities/note_names/AdvancedTimer.qml new file mode 100755
index 00000000..b7ae9af3
--- /dev/null
+++ b/src/activities/note_names/AdvancedTimer.qml
@@ -0,0 +1,67 @@
+/* GCompris - AdvancedTimer.qml
+ *
+ * Copyright (C) 2018 Aman Kumar Gupta <gupta2140@gmail.com>
+ *
+ * Authors:
+ *   Beth Hadley <bethmhadley@gmail.com> (GTK+ version)
+ *   Johnny Jazeix <jazeix@gmail.com> (Qt Quick port)
+ *   Aman Kumar Gupta <gupta2140@gmail.com> (Qt Quick port)
+ *
+ *   This program is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU General Public License as published by
+ *   the Free Software Foundation; either version 3 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This program is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *   GNU General Public License for more details.
+ *
+ *   You should have received a copy of the GNU General Public License
+ *   along with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+import QtQuick 2.1
+import QtQuick.Controls 1.0
+import GCompris 1.0
+import "note_names.js" as Activity
+
+Timer {
+    id: timer
+
+    property double startTime
+    property double pauseTime
+    property int timerNormalInterval: 2000
+    property int remainingInterval
+
+    interval: timerNormalInterval
+
+    signal pause
+    signal resume
+
+    onPause: {
+        if(timer.running) {
+            pauseTime = new Date().getTime()
+            timer.stop()
+        }
+    }
+
+    onResume: {
+        if(!timer.running) {
+            remainingInterval = Math.abs(timer.interval - Math.abs(pauseTime - \
startTime)) +            timer.interval = remainingInterval
+            timer.start()
+        }
+    }
+
+    onTriggered:{
+        if(interval != timerNormalInterval) {
+            interval = timerNormalInterval
+        }
+        triggeredOnStart = false
+    }
+
+    onRunningChanged: {
+        if(running)
+            startTime = new Date().getTime()
+    }
+}
diff --git a/src/activities/note_names/NoteNames.qml \
b/src/activities/note_names/NoteNames.qml index d579f2f5..f078f132 100755
--- a/src/activities/note_names/NoteNames.qml
+++ b/src/activities/note_names/NoteNames.qml
@@ -48,6 +48,59 @@ ActivityBase {
             activity.stop.connect(stop)
         }
 
+        Keys.onPressed: {
+            if(event.key === Qt.Key_1) {
+                if(Activity.sequence[0][0] === 'C')
+                    Activity.checkAnswer(Activity.sequence[0])
+                else
+                   Activity.checkAnswer("Z")
+            }
+            else if(event.key === Qt.Key_2) {
+                if(Activity.sequence[0][0] === 'D')
+                    Activity.checkAnswer(Activity.sequence[0])
+                else
+                   Activity.checkAnswer("Z")
+            }
+            else if(event.key === Qt.Key_3) {
+                if(Activity.sequence[0][0] === 'E')
+                    Activity.checkAnswer(Activity.sequence[0])
+                else
+                   Activity.checkAnswer("Z")
+            }
+            else if(event.key === Qt.Key_4) {
+                if(Activity.sequence[0][0] === 'F')
+                    Activity.checkAnswer(Activity.sequence[0])
+                else
+                   Activity.checkAnswer("Z")
+            }
+            else if(event.key === Qt.Key_5) {
+                if(Activity.sequence[0][0] === 'G')
+                    Activity.checkAnswer(Activity.sequence[0])
+                else
+                   Activity.checkAnswer("Z")
+            }
+            else if(event.key === Qt.Key_6) {
+                if(Activity.sequence[0][0] === 'A')
+                    Activity.checkAnswer(Activity.sequence[0])
+                else
+                   Activity.checkAnswer("Z")
+            }
+            else if(event.key === Qt.Key_7) {
+                if(Activity.sequence[0][0] === 'B')
+                    Activity.checkAnswer(Activity.sequence[0])
+                else
+                   Activity.checkAnswer("Z")
+            }
+            else if(event.key === Qt.Key_Left && shiftKeyboardLeft.visible) {
+                piano.currentOctaveNb--
+            }
+            else if(event.key === Qt.Key_Right && shiftKeyboardRight.visible) {
+                piano.currentOctaveNb++
+            }
+            else
+                Activity.checkAnswer("Z")
+        }
+
         // Add here the QML items you need to access in javascript
         QtObject {
             id: items
@@ -61,15 +114,14 @@ ActivityBase {
             property alias bonus: bonus
             property alias iAmReady: iAmReady
             property alias wrongAnswerAnimation: wrongAnswerAnimation
-            property alias dataset: dataset
             property alias messageBox: messageBox
+            property alias addNoteTimer: addNoteTimer
+            property alias parser: parser
             property bool isTutorialMode: true
         }
 
-        Loader {
-            id: dataset
-            asynchronous: false
-            source: "qrc:/gcompris/src/activities/note_names/resource/dataset.qml"
+        JsonParser {
+            id: parser
         }
 
         onStart: { Activity.start(items) }
@@ -85,14 +137,24 @@ ActivityBase {
             to: 0.4
             duration: 2000
             onStarted: {
-                multipleStaff.stopNoteAnimation()
+                multipleStaff.pauseNoteAnimation()
+                addNoteTimer.pause()
                 messageBox.visible = true
                 colorLayer.color = "red"
             }
             onStopped: {
-                Activity.wrongAnswer()
                 messageBox.visible = false
                 colorLayer.color = "black"
+                if(Activity.sequence[Activity.noteIndexToDisplay] == undefined) {
+                    addNoteTimer.triggeredOnStart = true
+                    Activity.noteIndexToDisplay--
+                    Activity.wrongAnswer()
+                    addNoteTimer.start()
+                }
+                else {
+                    Activity.wrongAnswer()
+                    addNoteTimer.resume()
+                }
             }
         }
 
@@ -140,6 +202,7 @@ ActivityBase {
                 anchors.fill: parent
                 enabled: items.isTutorialMode
                 onClicked: {
+                    items.multipleStaff.pauseNoteAnimation()
                     items.multipleStaff.musicElementModel.remove(1)
                     Activity.showTutorial()
                 }
@@ -167,6 +230,15 @@ ActivityBase {
             }
         }
 
+        AdvancedTimer {
+            id: addNoteTimer
+            onTriggered: {
+                if(Activity.sequence[++Activity.noteIndexToDisplay] != undefined) {
+                    \
Activity.displayNote(Activity.sequence[Activity.noteIndexToDisplay]) +                \
} +            }
+        }
+
         MultipleStaff {
             id: multipleStaff
             width: horizontalLayout ? parent.width * 0.5 : parent.width * 0.76
diff --git a/src/activities/note_names/note_names.js \
b/src/activities/note_names/note_names.js index cc69406b..c5b93632 100755
--- a/src/activities/note_names/note_names.js
+++ b/src/activities/note_names/note_names.js
@@ -29,15 +29,18 @@ var items
 var dataset
 var correctAnswerCount = []
 var sequence
+var noteIndexToDisplay
 
 function start(items_) {
     items = items_
     currentLevel = 0
-    dataset = items.dataset.item.levels
+    dataset = items.parser.parseFromUrl("qrc:/gcompris/src/activities/note_names/resource/dataset_01.json").levels
  numberOfLevel = dataset.length
 }
 
 function stop() {
+    items.addNoteTimer.stop()
+    items.multipleStaff.pauseNoteAnimation()
 }
 
 function initLevel() {
@@ -47,8 +50,9 @@ function initLevel() {
     items.background.clefType = dataset[currentLevel]["clef"]
     items.piano.currentOctaveNb = 1
     items.piano2.currentOctaveNb = 1
-    items.multipleStaff.stopNoteAnimation()
+    items.multipleStaff.pauseNoteAnimation()
     items.wrongAnswerAnimation.stop()
+    items.addNoteTimer.stop()
     items.multipleStaff.initClefs(items.background.clefType)
     sequence = JSON.parse(JSON.stringify(dataset[currentLevel]["sequence"]))
     items.isTutorialMode = true
@@ -69,6 +73,7 @@ function showTutorial() {
 }
 
 function startGame() {
+    noteIndexToDisplay = 0
     sequence = JSON.parse(JSON.stringify(dataset[currentLevel]["sequence"]))
     for(var i = 0; i < 2; i++) {
         for(var j = 0; j < dataset[currentLevel]["sequence"].length; j++)
@@ -80,6 +85,9 @@ function startGame() {
 
 function displayNote(currentNote) {
     items.multipleStaff.addMusicElement("note", currentNote, "Quarter", false, \
false, items.background.clefType) +    if(!items.isTutorialMode) {
+        items.addNoteTimer.start()
+    }
 }
 
 function wrongAnswer() {
@@ -90,6 +98,7 @@ function wrongAnswer() {
         }
 
         correctAnswerCount[sequence[0]] = 0
+        noteIndexToDisplay--
 
         if(sequence[sequence.length - 1] != sequence[0])
             sequence.push(sequence.shift())
@@ -103,25 +112,25 @@ function wrongAnswer() {
         for(var i = 0; i < sequence.length; i++) {
             console.log(sequence[i])
         }
-
-        displayNote(sequence[0])
+        items.multipleStaff.resumeNoteAnimation()
     }
 }
 
 function correctAnswer() {
     if(correctAnswerCount[sequence[0]] == undefined)
-        correctAnswerCount[sequence[0]] = 0
+            correctAnswerCount[sequence[0]] = 0
 
     correctAnswerCount[sequence[0]]++
+    noteIndexToDisplay--
+    items.multipleStaff.pauseNoteAnimation()
     items.multipleStaff.musicElementModel.remove(1)
+    items.multipleStaff.resumeNoteAnimation()
     sequence.shift()
     console.log("Correct answer...New sequence:")
     for(var i = 0; i < sequence.length; i++) {
         console.log(sequence[i])
     }
-    if(sequence.length != 0)
-        displayNote(sequence[0])
-    else
+    if(sequence.length === 0)
         items.bonus.good("flower")
 }
 
diff --git a/src/activities/note_names/resource/dataset.qml \
b/src/activities/note_names/resource/dataset_01.json similarity index 61%
rename from src/activities/note_names/resource/dataset.qml
rename to src/activities/note_names/resource/dataset_01.json
index da1d26ef..da4492d9 100644
--- a/src/activities/note_names/resource/dataset.qml
+++ b/src/activities/note_names/resource/dataset_01.json
@@ -1,29 +1,5 @@
-/* GCompris - dataset.qml
- *
- * Copyright (C) 2018 Aman Kumar Gupta <gupta2140@gmail.com>
- *
- * Authors:
- *   Beth Hadley <bethmhadley@gmail.com> (GTK+ version)
- *   Aman Kumar Gupta <gupta2140@gmail.com> (Qt Quick port)
- *
- *   This program is free software; you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 3 of the License, or
- *   (at your option) any later version.
- *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY; without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *   GNU General Public License for more details.
- *
- *   You should have received a copy of the GNU General Public License
- *   along with this program; if not, see <http://www.gnu.org/licenses/>.
- **/
-import QtQuick 2.6
-
-QtObject {
-    // These levels teach from notes F1 to D6.
-    property var levels: [
+{
+    "levels": [
         {
             "clef": "Treble",
             "sequence": ["C4", "G4"]
@@ -96,5 +72,6 @@ QtObject {
             "clef": "Bass",
             "sequence": ["F1", "G1", "A1"]
         }
-    ]
+    ],
+    "objective": "This dataset teaches notes from F1 to D6."
 }
diff --git a/src/activities/piano_composition/MultipleStaff.qml \
b/src/activities/piano_composition/MultipleStaff.qml index c5d59f01..12673bd9 100644
--- a/src/activities/piano_composition/MultipleStaff.qml
+++ b/src/activities/piano_composition/MultipleStaff.qml
@@ -203,11 +203,18 @@ Item {
     }
 
     /**
-     * Stops the sliding animation of the notes.
+     * Pauses the sliding animation of the notes.
      */
-    function stopNoteAnimation() {
+    function pauseNoteAnimation() {
         for(var i = 0; i < musicElementModel.count; i++) {
-            musicElementRepeater.itemAt(i).noteAnimation.stop()
+            if(musicElementRepeater.itemAt(i).noteAnimation.running)
+                musicElementRepeater.itemAt(i).noteAnimation.pause()
+        }
+    }
+
+    function resumeNoteAnimation() {
+        for(var i = 0; i < musicElementModel.count; i++) {
+            musicElementRepeater.itemAt(i).noteAnimation.resume()
         }
     }
 
@@ -244,7 +251,7 @@ Item {
                 isNextStaff = true
         }
 
-        if(isNextStaff) {
+        if(isNextStaff && !noteAnimationEnabled) {
             multipleStaff.currentEnteringStaff++
             if(multipleStaff.currentEnteringStaff >= multipleStaff.nbStaves)
                 multipleStaff.nbStaves++
@@ -382,6 +389,7 @@ Item {
                 }
                 audioLooper.stop()
                 var noteToPlay = \
"qrc:/gcompris/src/activities/piano_composition/resource/" + soundPitch.toLowerCase() \
+ "_pitches/" + noteName + ".wav" +                console.log(noteToPlay)
                 audioLooper.playMusic(noteToPlay, duration)
             }
         }
diff --git a/src/activities/piano_composition/OptionsRow.qml \
b/src/activities/piano_composition/OptionsRow.qml index 1cf71c85..51e21245 100644
--- a/src/activities/piano_composition/OptionsRow.qml
+++ b/src/activities/piano_composition/OptionsRow.qml
@@ -68,6 +68,7 @@ Row {
         id: noteOptions
         source: "qrc:/gcompris/src/activities/piano_composition/resource/genericNote%1.svg".arg(optionsRow.noteLengthName[currentIndex][1])
  nbOptions: optionsRow.noteLengthName.length
+        currentIndex: 2
         onClicked: {
             background.currentType = optionsRow.noteLengthName[currentIndex][1]
             emitOptionMessage(optionsRow.noteLengthName[currentIndex][0])
diff --git a/src/activities/piano_composition/Piano_composition.qml \
b/src/activities/piano_composition/Piano_composition.qml index 63740551..5e5bbaec \
                100644
--- a/src/activities/piano_composition/Piano_composition.qml
+++ b/src/activities/piano_composition/Piano_composition.qml
@@ -136,8 +136,8 @@ ActivityBase {
         onStart: { Activity.start(items) }
         onStop: { Activity.stop() }
 
-        property string currentType: "Whole"
-        property string restType: "Whole"
+        property string currentType: "Quarter"
+        property string restType: "Quarter"
         property string clefType: bar.level == 2 ? "Bass" : "Treble"
         property bool isLyricsMode: (optionsRow.lyricsOrPianoModeIndex === 1) && \
optionsRow.lyricsOrPianoModeOptionVisible  
diff --git a/src/activities/piano_composition/piano_composition.js \
b/src/activities/piano_composition/piano_composition.js index 8894e5c9..e768c487 \
                100644
--- a/src/activities/piano_composition/piano_composition.js
+++ b/src/activities/piano_composition/piano_composition.js
@@ -105,6 +105,8 @@ function initLevel() {
 
     items.piano.currentOctaveNb = items.piano.defaultOctaveNb
     items.multipleStaff.nbStaves = 2
+    items.optionsRow.noteOptionsIndex = 2
+    items.background.currentType = "Quarter"
     items.lyricsArea.resetLyricsArea()
     undoStack = []
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic