[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [gcompris/playpiano] src: Piano_composition: Append melodies during save
From: Divyam Madaan <null () kde ! org>
Date: 2017-08-31 20:40:53
Message-ID: E1dnWGj-0001Yx-19 () code ! kde ! org
[Download RAW message or body]
Git commit b6323e0b462ed6c85062a4c236177149257433f2 by Divyam Madaan.
Committed on 31/08/2017 at 20:39.
Pushed by dmadaan into branch 'playpiano'.
Piano_composition: Append melodies during save
M +2 -2 src/activities/piano_composition/MultipleStaff.qml
M +1 -1 src/activities/piano_composition/Piano_composition.qml
M +35 -19 src/activities/piano_composition/piano_composition.js
M +24 -0 src/core/File.cpp
M +10 -0 src/core/File.h
https://commits.kde.org/gcompris/b6323e0b462ed6c85062a4c236177149257433f2
diff --git a/src/activities/piano_composition/MultipleStaff.qml \
b/src/activities/piano_composition/MultipleStaff.qml index 0ef67921..9ea33c29 100644
--- a/src/activities/piano_composition/MultipleStaff.qml
+++ b/src/activities/piano_composition/MultipleStaff.qml
@@ -95,8 +95,8 @@ Item {
var staveNotes = staves.itemAt(i).notes
for(var j = 0; j < staveNotes.count; j++) {
melody.push({
- "type": staves.itemAt(i).notes.get(j).type,
- "note": staves.itemAt(i).notes.get(j).mValue
+ "type": staveNotes.get(j).type,
+ "note": staveNotes.get(j).mValue
})
}
}
diff --git a/src/activities/piano_composition/Piano_composition.qml \
b/src/activities/piano_composition/Piano_composition.qml index f46a47b9..81d313b2 \
100644
--- a/src/activities/piano_composition/Piano_composition.qml
+++ b/src/activities/piano_composition/Piano_composition.qml
@@ -171,7 +171,7 @@ ActivityBase {
verticalAlignment: Text.AlignVCenter
fontSizeMode: Text.Fit
wrapMode: Text.WordWrap
- text: Activity.instructions[bar.level - 1]
+ text: Activity.instructions[bar.level - 1].text
}
}
diff --git a/src/activities/piano_composition/piano_composition.js \
b/src/activities/piano_composition/piano_composition.js index 91b0d2fe..9db6b700 \
100644
--- a/src/activities/piano_composition/piano_composition.js
+++ b/src/activities/piano_composition/piano_composition.js
@@ -28,13 +28,30 @@ var currentLevel = 0
var numberOfLevel = 7
var items
var userDir = "file://" + GCompris.ApplicationInfo.getSharedWritablePath() + "/" + \
"piano_composition"
-var userFile = "file://" + GCompris.ApplicationInfo.getSharedWritablePath() + "/" + \
"piano_composition" + "/melodies.json"
-var instructions = ["This is the treble cleff staff for high pitched notes",
- "This is the bass cleff staff for low pitched notes",
- "Click on the note symbols to write different length notes such \
as quarter notes, half notes and whole notes", "The black keys are sharp and flat \
keys, have a # sign.",
- "Each black key has two names: flat and sharp. Flat notes have b \
sign",
- "Now you can load music",
- "Now you can compose your own music"]
+var userFile = userDir + "/melodies.json"
+var instructions = [{
+ "text": qsTr("This is the treble cleff staff for high pitched notes")
+ },
+ {
+ "text": qsTr("This is the bass cleff staff for low pitched notes")
+ },
+ {
+ "text": qsTr("Click on the note symbols to write different length notes such \
as quarter notes, half notes and whole notes") + },
+ {
+ "text": qsTr("The black keys are sharp and flat keys, have a # sign.")
+ },
+ {
+ "text": qsTr("Each black key has two names: flat and sharp. Flat notes have \
b sign") + },
+ {
+ "text": qsTr("Now you can load music")
+
+ },
+ {
+ "text": qsTr("Now you can compose your own music")
+ }
+]
function start(items_) {
items = items_
@@ -51,22 +68,21 @@ function saveMelody() {
console.debug("Created directory " + userDir);
}
- if (!items.file.write(JSON.stringify(notes), userFile)) {
+ var data = items.file.read(userFile)
+ if (!items.file.append(JSON.stringify(notes), userFile)) {
Core.showMessageDialog(items.background,
- qsTr("Error saving melody to your file (%1)")
- .arg(userFile),
- "", null, "", null, null);
- }
- else {
+ qsTr("Error saving melody to your file (%1)")
+ .arg(userFile),
+ "", null, "", null, null);
+ } else {
Core.showMessageDialog(items.background,
- qsTr("Saved melody to your file (%1)")
- .arg(userFile),
- "", null, "", null, null);
+ qsTr("Saved melody to your file (%1)")
+ .arg(userFile),
+ "", null, "", null, null);
}
}
-function stop() {
-}
+function stop() {}
function initLevel() {
items.bar.level = currentLevel + 1
@@ -74,7 +90,7 @@ function initLevel() {
function nextLevel() {
items.staff2.eraseAllNotes()
- if(numberOfLevel <= ++currentLevel ) {
+ if(numberOfLevel <= ++currentLevel) {
currentLevel = 0
}
initLevel();
diff --git a/src/core/File.cpp b/src/core/File.cpp
index 00169b0b..c18270d2 100644
--- a/src/core/File.cpp
+++ b/src/core/File.cpp
@@ -115,6 +115,30 @@ bool File::write(const QString& data, const QString& name)
return true;
}
+bool File::append(const QString& data, const QString& name)
+{
+ if (!name.isEmpty())
+ setName(name);
+
+ if (m_name.isEmpty()) {
+ emit error("source is empty");
+ return false;
+ }
+
+ QFile file(m_name);
+ if (!file.open(QFile::WriteOnly | QFile::Append)) {
+ emit error("could not open file " + m_name);
+ return false;
+ }
+
+ QTextStream out(&file);
+ out << data;
+
+ file.close();
+
+ return true;
+}
+
void File::init()
{
qmlRegisterType<File>("GCompris", 1, 0, "File");
diff --git a/src/core/File.h b/src/core/File.h
index 04a2a9b5..bb58834d 100644
--- a/src/core/File.h
+++ b/src/core/File.h
@@ -70,6 +70,16 @@ public:
*/
Q_INVOKABLE bool write(const QString& data, const QString& name = QString());
+ /**
+ * Apends @p data to a file.
+ *
+ * @param data Text data to appends.
+ * @param name [optional] Filename to append to. If omitted writes to
+ * the file specified by the member name.
+ * @returns success of the operation.
+ * @sa name
+ */
+ Q_INVOKABLE bool append(const QString& data, const QString& name = QString());
/**
* Checks whether file @p path exists.
*
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic