diff --git a/src/activities/piano_composition/MultipleStaff.qml b/src/activities/piano_composition/MultipleStaff.qml --- a/src/activities/piano_composition/MultipleStaff.qml +++ b/src/activities/piano_composition/MultipleStaff.qml @@ -29,7 +29,7 @@ property int nbStaves property string clef - property int distanceBetweenStaff: 20 + property int distanceBetweenStaff: multipleStaff.height / 8 property int currentStaff: 0 @@ -39,22 +39,34 @@ property bool noteIsColored property bool isMetronomeDisplayed: false - Column { - spacing: parent.height * 0.05 - Repeater { - id: staves - model: nbStaves - Staff { - id: staff - clef: multipleStaff.clef - height: (multipleStaff.height - distanceBetweenStaff * (nbStaves - 1)) / nbStaves - width: multipleStaff.width - y: index * (height + distanceBetweenStaff) - lastPartition: index == nbStaves - 1 - nbMaxNotesPerStaff: multipleStaff.nbMaxNotesPerStaff - noteIsColored: multipleStaff.noteIsColored - isMetronomeDisplayed: multipleStaff.isMetronomeDisplayed - firstNoteX: multipleStaff.firstNoteX + property alias flickableStaves: flickableStaves + + Flickable { + id: flickableStaves + flickableDirection: Flickable.VerticalFlick + contentWidth: staffColumn.width + contentHeight: staffColumn.height + multipleStaff.height / 7 + anchors.fill: parent + clip: true + Column { + id: staffColumn + spacing: distanceBetweenStaff + anchors.top: parent.top + anchors.topMargin: multipleStaff.height / 14 + Repeater { + id: staves + model: nbStaves + Staff { + id: staff + clef: multipleStaff.clef + height: multipleStaff.height / 5 + width: multipleStaff.width - 5 + lastPartition: index == (nbStaves - 1) + nbMaxNotesPerStaff: multipleStaff.nbMaxNotesPerStaff + noteIsColored: multipleStaff.noteIsColored + isMetronomeDisplayed: multipleStaff.isMetronomeDisplayed + firstNoteX: multipleStaff.firstNoteX + } } } } @@ -62,10 +74,13 @@ function addNote(newValue_, newType_, newBlackType_, highlightWhenPlayed_) { if(staves.itemAt(currentStaff).notes.count > nbMaxNotesPerStaff) { if(currentStaff + 1 >= nbStaves) { - return + var melody = getAllNotes() + nbStaves++ + flickableStaves.flick(0, - nbStaves * multipleStaff.height) + currentStaff = 0 + loadFromData(melody) } - else - currentStaff++ + currentStaff++ } staves.itemAt(currentStaff).addNote(newValue_, newType_, newBlackType_, highlightWhenPlayed_); @@ -89,24 +104,28 @@ currentStaff = 0; } + readonly property var whiteNotes: ["C", "D", "E", "F", "G", "A", "B", "2C", "2D", "2E", "2F"] + readonly property var blackNotesSharp: ["C#", "D#", "F#", "G#", "A#", "2C#"] + readonly property var blackNotesFlat: ["DB", "EB", "GB", "AB", "BB"] + function getAllNotes() { - var melody = [] + var melody = "" + multipleStaff.clef for(var i = 0; i < nbStaves; i ++) { var staveNotes = staves.itemAt(i).notes for(var j = 0; j < staveNotes.count; j++) { - melody.push({ - "type": staveNotes.get(j).type, - "note": staveNotes.get(j).mValue - }) - } + var noteValue = staveNotes.get(j).mValue + if(noteValue > 0) + melody = melody + " " + whiteNotes[noteValue - 1] + else if(staveNotes.get(j).mBlackType === "sharp") + melody = melody + " " + blackNotesSharp[Math.abs(noteValue) - 1] + else + melody = melody + " " + blackNotesFlat[Math.abs(noteValue) - 1] + melody = melody + staveNotes.get(j).mType + } } return melody } - property var whiteNotes: ["C", "D", "E", "F", "G", "A", "B", "2C", "2D", "2E", "2F"] - property var blackNotesSharp: ["C#", "D#", "F#", "G#", "A#", "2C#"] - property var blackNotesFlat: ["DB", "EB", "GB", "AB", "BB"] - function loadFromData(data) { eraseAllNotes() var melody = data.split(" "); @@ -124,8 +143,6 @@ else { addNote("" + (-1 * blackNotesFlat.indexOf(noteStr) - 1), type, "flat", false); } - - print(melody[i]); } } diff --git a/src/activities/piano_composition/Piano_composition.qml b/src/activities/piano_composition/Piano_composition.qml --- a/src/activities/piano_composition/Piano_composition.qml +++ b/src/activities/piano_composition/Piano_composition.qml @@ -33,7 +33,7 @@ onStart: focus = true onStop: {} - property bool horizontalLayout: background.width > background.height ? true : false + property bool horizontalLayout: background.width > background.height pageComponent: Rectangle { id: background @@ -96,9 +96,7 @@ } function playNote(note) { - multipleStaff.addNote(note, currentType, piano.useSharpNotation ? "sharp" : "flat", false) - var noteToPlay = 'qrc:/gcompris/src/activities/piano_composition/resource/' + 'bass' + '_pitches/' + currentType + '/' + note + '.wav'; - items.audioEffects.play(noteToPlay) + piano.noteClicked(note) } // Add here the QML items you need to access in javascript QtObject { @@ -134,26 +132,11 @@ } } - MultipleStaff { - id: multipleStaff - width: horizontalLayout ? parent.width * 0.50 : parent.height * 0.8 - height: horizontalLayout ? parent.height * 0.5 : parent.height * 0.3 - nbStaves: 3 - clef: clefType - nbMaxNotesPerStaff: 8 - noteIsColored: true - isMetronomeDisplayed: true - anchors.right: parent.right - anchors.top: horizontalLayout ? instructionBox.bottom : piano.bottom - anchors.topMargin: horizontalLayout ? parent.height * 0.13 : parent.height * 0.05 - anchors.rightMargin: 20 - } - Rectangle { id: instructionBox radius: 10 - width: horizontalLayout ? background.width / 1.9 : background.width * 0.95 - height: horizontalLayout ? background.height / 5 : background.height / 9 + width: background.width * 0.98 + height: background.height / 9 anchors.horizontalCenter: parent.horizontalCenter opacity: 0.8 border.width: 6 @@ -175,18 +158,50 @@ } } + MultipleStaff { + id: multipleStaff + width: horizontalLayout ? parent.width * 0.50 : parent.width * 0.8 + height: horizontalLayout ? parent.height * 0.58 : parent.height * 0.3 + nbStaves: 3 + clef: clefType + nbMaxNotesPerStaff: 8 + noteIsColored: true + isMetronomeDisplayed: true + anchors.right: horizontalLayout ? parent.right: undefined + anchors.horizontalCenter: horizontalLayout ? undefined : parent.horizontalCenter + anchors.top: instructionBox.bottom + anchors.topMargin: parent.height * 0.1 + anchors.rightMargin: parent.width * 0.043 + } + + GCButtonScroll { + anchors.right: parent.right + anchors.rightMargin: 5 * ApplicationInfo.ratio + anchors.verticalCenter: multipleStaff.verticalCenter + width: horizontalLayout ? parent.width * 0.033 : parent.width * 0.06 + height: width * heightRatio + onUp: multipleStaff.flickableStaves.flick(0, multipleStaff.height * 1.3) + onDown: multipleStaff.flickableStaves.flick(0, -multipleStaff.height * 1.3) + upVisible: multipleStaff.flickableStaves.visibleArea.yPosition > 0 + downVisible: (multipleStaff.flickableStaves.visibleArea.yPosition + multipleStaff.flickableStaves.visibleArea.heightRatio) < 1 + } + Piano { id: piano - width: horizontalLayout ? parent.width * 0.4 : parent.width * 0.8 - height: horizontalLayout ? parent.height * 0.45 : parent.width * 0.3 + width: horizontalLayout ? parent.width * 0.4 : parent.width * 0.7 + height: horizontalLayout ? parent.height * 0.45 : parent.width * 0.26 anchors.horizontalCenter: horizontalLayout ? undefined : parent.horizontalCenter anchors.left: horizontalLayout ? parent.left : undefined - anchors.leftMargin: horizontalLayout ? parent.width * 0.06 : parent.height * 0.01 - anchors.top: optionsRow.bottom + anchors.leftMargin: parent.width * 0.03 + anchors.top: horizontalLayout ? optionsRow.bottom : multipleStaff.bottom + anchors.topMargin: parent.height * 0.05 blackLabelsVisible: [4, 5, 6, 7, 8].indexOf(items.bar.level) == -1 ? false : true useSharpNotation: bar.level == 5 ? false : true onNoteClicked: { - multipleStaff.addNote(note, currentType, piano.useSharpNotation ? "sharp" : "flat", false) + var blackType = "" + if(note < 0) + blackType = piano.useSharpNotation ? "sharp" : "flat" + multipleStaff.addNote(note, currentType, blackType, false) var noteToPlay = 'qrc:/gcompris/src/activities/piano_composition/resource/' + clefType + '_pitches/' + currentType + '/' + note + '.wav'; items.audioEffects.play(noteToPlay) } diff --git a/src/activities/piano_composition/Staff.qml b/src/activities/piano_composition/Staff.qml --- a/src/activities/piano_composition/Staff.qml +++ b/src/activities/piano_composition/Staff.qml @@ -177,17 +177,13 @@ } y: { - var shift = 0 + var shift = - verticalDistanceBetweenLines / 2 if(clef === "bass") { - shift = -2.5 * verticalDistanceBetweenLines + shift += -2.5 * verticalDistanceBetweenLines } - if(blackType !== "") { - if(blackType === "flat") { - shift += - verticalDistanceBetweenLines - } - else { - shift += - verticalDistanceBetweenLines / 2 - } + + if(blackType === "flat") { + shift += - verticalDistanceBetweenLines / 2 } if(mValue >= -2)