Changeset View
Changeset View
Standalone View
Standalone View
src/activities/piano_composition/MultipleStaff.qml
Context not available. | |||||
41 | 41 | | |||
---|---|---|---|---|---|
42 | property alias flickableStaves: flickableStaves | 42 | property alias flickableStaves: flickableStaves | ||
43 | 43 | | |||
44 | signal noteClicked(string noteName, string noteLength) | 44 | signal noteClicked(string noteName, string noteType) | ||
45 | 45 | | |||
46 | Flickable { | 46 | Flickable { | ||
47 | id: flickableStaves | 47 | id: flickableStaves | ||
Context not available. | |||||
90 | playNoteAudio(noteName, noteType) | 90 | playNoteAudio(noteName, noteType) | ||
91 | } | 91 | } | ||
92 | 92 | | |||
93 | function playNoteAudio(noteName, noteLength) { | 93 | function playNoteAudio(noteName, noteType) { | ||
94 | var audioPitchType | 94 | if(noteType != "Rest") { | ||
95 | // We should find a corresponding b type enharmonic notation for # type note to play the audio. | 95 | var audioPitchType | ||
96 | if(noteName[1] === "#") { | 96 | // We should find a corresponding b type enharmonic notation for # type note to play the audio. | ||
97 | var pianoBlackKeysFlat | 97 | if(noteName[1] === "#") { | ||
98 | var pianoBlackKeysSharp | 98 | var pianoBlackKeysFlat | ||
99 | if(background.clefType === "treble") { | 99 | var pianoBlackKeysSharp | ||
100 | pianoBlackKeysFlat = piano.blackNotesFlatTreble | 100 | if(background.clefType === "treble") { | ||
101 | pianoBlackKeysSharp = piano.blackNotesSharpTreble | 101 | pianoBlackKeysFlat = piano.blackNotesFlatTreble | ||
102 | } | 102 | pianoBlackKeysSharp = piano.blackNotesSharpTreble | ||
103 | else { | 103 | } | ||
104 | pianoBlackKeysFlat = piano.blackNotesFlatBass | 104 | else { | ||
105 | pianoBlackKeysSharp = piano.blackNotesSharpBass | 105 | pianoBlackKeysFlat = piano.blackNotesFlatBass | ||
106 | } | 106 | pianoBlackKeysSharp = piano.blackNotesSharpBass | ||
107 | } | ||||
107 | 108 | | |||
108 | var foundNote = false | 109 | var foundNote = false | ||
109 | for(var i = 0; (i < pianoBlackKeysSharp.length) && !foundNote; i++) { | 110 | for(var i = 0; (i < pianoBlackKeysSharp.length) && !foundNote; i++) { | ||
110 | for(var j = 0; j < pianoBlackKeysSharp[i].length; j++) { | 111 | for(var j = 0; j < pianoBlackKeysSharp[i].length; j++) { | ||
111 | if(pianoBlackKeysSharp[i][j][0] === noteName) { | 112 | if(pianoBlackKeysSharp[i][j][0] === noteName) { | ||
112 | noteName = pianoBlackKeysFlat[i][j][0] | 113 | noteName = pianoBlackKeysFlat[i][j][0] | ||
113 | foundNote = true | 114 | foundNote = true | ||
114 | break | 115 | break | ||
116 | } | ||||
115 | } | 117 | } | ||
116 | } | 118 | } | ||
117 | } | | |||
118 | 119 | | |||
119 | audioPitchType = parseInt(noteName[2]) | 120 | audioPitchType = parseInt(noteName[2]) | ||
121 | } | ||||
122 | else if(noteName[1] === "b") | ||||
123 | audioPitchType = parseInt(noteName[2]) | ||||
124 | else | ||||
125 | audioPitchType = parseInt(noteName[1]) | ||||
126 | | ||||
127 | if(audioPitchType > 3) | ||||
128 | audioPitchType = "treble" | ||||
129 | else | ||||
130 | audioPitchType = "bass" | ||||
131 | var noteToPlay = "qrc:/gcompris/src/activities/piano_composition/resource/" + audioPitchType + "_pitches/" + noteName + ".wav" | ||||
132 | items.audioEffects.play(noteToPlay) | ||||
120 | } | 133 | } | ||
121 | else if(noteName[1] === "b") | | |||
122 | audioPitchType = parseInt(noteName[2]) | | |||
123 | else | | |||
124 | audioPitchType = parseInt(noteName[1]) | | |||
125 | | ||||
126 | if(audioPitchType > 3) | | |||
127 | audioPitchType = "treble" | | |||
128 | else | | |||
129 | audioPitchType = "bass" | | |||
130 | var noteToPlay = "qrc:/gcompris/src/activities/piano_composition/resource/" + audioPitchType + "_pitches/" + noteName + ".wav" | | |||
131 | items.audioEffects.play(noteToPlay) | | |||
132 | } | 134 | } | ||
133 | 135 | | |||
134 | function getAllNotes() { | 136 | function getAllNotes() { | ||
Context not available. | |||||
144 | 146 | | |||
145 | function loadFromData(data) { | 147 | function loadFromData(data) { | ||
146 | eraseAllNotes() | 148 | eraseAllNotes() | ||
147 | var melody = data.split(" "); | 149 | var melody = data.split(" ") | ||
148 | multipleStaff.clef = melody[0]; | 150 | multipleStaff.clef = melody[0] | ||
149 | for(var i = 1 ; i < melody.length ; ++ i) { | 151 | for(var i = 1 ; i < melody.length ; ++ i) { | ||
150 | var noteLength = melody[i].length; | 152 | var noteLength = melody[i].length | ||
151 | var noteName = melody[i][0] | 153 | var noteName = melody[i][0] | ||
152 | var noteType | 154 | var noteType | ||
153 | if(melody[i][1] === "#" || melody[i][1] === "b") { | 155 | if(melody[i].substring(noteLength - 4, noteLength) === "Rest") { | ||
156 | noteName = melody[i].substring(0, noteLength - 4) | ||||
157 | noteType = "Rest" | ||||
158 | } | ||||
159 | else if(melody[i][1] === "#" || melody[i][1] === "b") { | ||||
154 | noteType = melody[i].substring(3, melody[i].length) | 160 | noteType = melody[i].substring(3, melody[i].length) | ||
155 | noteName += melody[i][1] + melody[i][2]; | 161 | noteName += melody[i][1] + melody[i][2]; | ||
156 | } | 162 | } | ||
Context not available. | |||||
165 | 171 | | |||
166 | function eraseAllNotes() { | 172 | function eraseAllNotes() { | ||
167 | for(var v = 0 ; v <= currentStaff ; ++ v) | 173 | for(var v = 0 ; v <= currentStaff ; ++ v) | ||
168 | staves.itemAt(v).eraseAllNotes(); | 174 | staves.itemAt(v).eraseAllNotes() | ||
169 | currentStaff = 0; | 175 | currentStaff = 0 | ||
170 | } | 176 | } | ||
171 | 177 | | |||
172 | function play() { | 178 | function play() { | ||
Context not available. |