Skip to content
Permalink
Browse files

Merge pull request #2412 from jeetee/fix_cursor_addNote_cursor_position

Fix #100181 cursor addNote segment reference
  • Loading branch information...
lasconic committed Mar 29, 2016
2 parents 73f7e7a + 3ce4f22 commit 386bb4f203125738d9ad85f7fbb362e323028dad
@@ -159,6 +159,7 @@ void Cursor::addNote(int pitch)
{
NoteVal nval(pitch);
_score->addPitch(nval, false);
_segment = _score->inputState().segment();
}

//---------------------------------------------------------
@@ -13,8 +13,7 @@

subdirs(
album barline beam breath chordsymbol clef clef_courtesy compat concertpitch copypaste
copypastesymbollist dynamic earlymusic element hairpin instrumentchange join keysig layout links parts measure midi
midimapping note plugins repeat selectionfilter selectionrangedelete spanners split splitstaff timesig tools transpose tuplet text
copypastesymbollist cursor dynamic earlymusic element hairpin instrumentchange join keysig layout links parts measure midi midimapping note plugins repeat selectionfilter selectionrangedelete spanners split splitstaff timesig tools transpose tuplet text
)

install(FILES
@@ -0,0 +1,17 @@
#=============================================================================
# MuseScore
# Music Composition & Notation
# $Id:$
#
# Copyright (C) 2011 Werner Schweer
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2
# as published by the Free Software Foundation and appearing in
# the file LICENSE.GPL
#=============================================================================

set(TARGET tst_cursor)

include(${PROJECT_SOURCE_DIR}/mtest/cmake.inc)

@@ -0,0 +1,77 @@
//=============================================================================
// MuseScore
// Music Composition & Notation
//
// Copyright (C) 2012 Werner Schweer
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License version 2
// as published by the Free Software Foundation and appearing in
// the file LICENCE.GPL
//=============================================================================

#include <QtTest/QtTest>
#include "mtest/testutils.h"

#include "libmscore/cursor.h"
#include "libmscore/score.h"

using namespace Ms;

//---------------------------------------------------------
// TestCursor
//---------------------------------------------------------

class TestCursor : public QObject, public MTest
{
Q_OBJECT

private slots:
void initTestCase();
void testAddNoteTickUpdate();
};

//---------------------------------------------------------
// initTestCase
//---------------------------------------------------------

void TestCursor::initTestCase()
{
initMTest();
}

//---------------------------------------------------------
/// testAddTickUpdate
/// Add an element (note) and verify the tick updated with the correct amount
//---------------------------------------------------------

void TestCursor::testAddNoteTickUpdate()
{
//test setup
score = new Score();
score->appendPart("voice");
score->appendMeasures(2);
Cursor c(score);
//creation of cursor - check default values
QCOMPARE(c.score(), score);
QCOMPARE(c.track(), 0);
QCOMPARE(c.voice(), 0);
QCOMPARE(c.tick(), 0);
QVERIFY(c.segment() == nullptr);
//set the cursor at input position (start of score)
c.rewind(0);
QVERIFY(c.segment() != nullptr);

//actual test
//add 4 times a 1/8th, totalling a half note
c.setDuration(1, 8);
c.addNote(60);
c.addNote(60);
c.addNote(60);
c.addNote(60);
QCOMPARE(c.tick(), MScore::division * 2); //one division == 1 crotchet
}

QTEST_MAIN(TestCursor)
#include "tst_cursor.moc"

@@ -2,7 +2,7 @@ import QtQuick 2.1
import MuseScore 1.0

MuseScore {
version: "2.0"
version: "2.1"
description: "Create random score."
menuPath: "Plugins.random"
requiresScore: false
@@ -20,7 +20,7 @@ MuseScore {
}

onRun: {
var measures = 18;
var measures = 18; //in 4/4 default time signature
var numerator = 3;
var denominator = 4;
var octaves = 2;
@@ -41,26 +41,23 @@ MuseScore {
cursor.add(ts);

cursor.rewind(0);
cursor.setDuration(1, denominator);

var realMeasures = Math.floor((measures + numerator - 1) / numerator);
var realMeasures = Math.ceil(measures * denominator / numerator);
console.log(realMeasures);
var notes = realMeasures * numerator;
var notes = realMeasures * 4; //number of 1/4th notes

for (var i = 0; i < notes; ++i) {

if (Math.random() < 0.5) {
cursor.setDuration(1, 8);
addNote(key, cursor);
cursor.next();
addNote(key, cursor);
}
else {
cursor.setDuration(1, 4);
addNote(key, cursor);
}

cursor.next();
}
Qt.quit();
}
@@ -4,7 +4,7 @@ import QtQuick.Controls 1.0
import QtQuick.Layouts 1.0

MuseScore {
version: "2.0"
version: "2.1"
description: "Create random score."
menuPath: "Plugins.random2"
requiresScore: false
@@ -13,8 +13,6 @@ MuseScore {
width: 150
height: 75

property variant octaves : 2;

onRun: { }

function addNote(key, cursor) {
@@ -23,22 +21,22 @@ MuseScore {
var keyo = [ 0, 7, 2, 4 ];

var idx = Math.random() * 6;
var octave = Math.floor(Math.random() * 2);
var octave = Math.floor(Math.random() * octaves.value);
var pitch = cdur[Math.floor(idx)] + octave * 12 + 60;
var pitch = pitch + keyo[key];
console.log("Add note pitch "+pitch);
cursor.addNote(pitch);
}

function createScore() {
var measures = 18;
var measures = 18; //in 4/4 default time signature
var numerator = 3;
var denominator = 4;
var key = 3;
var key = 2; //index in keyo from addNote function above

var score = newScore("Random2.mscz", "piano", measures);

score.startCmd()
score.startCmd();
score.addText("title", "==Random2==");
score.addText("subtitle", "Another subtitle");

@@ -51,32 +49,32 @@ MuseScore {
ts.setSig(numerator, denominator);
cursor.add(ts);

cursor.rewind(0);
cursor.setDuration(1, denominator);

var realMeasures = Math.floor((measures * 2 + numerator - 1) / numerator);
var realMeasures = Math.ceil(measures * denominator / numerator);
console.log(realMeasures);
var notes = realMeasures * numerator;

for (var i = 0; i < notes; ++i) {
if (Math.random() < 0.5) {
console.log("Adding two notes at ", i);
cursor.setDuration(1, 8);
addNote(key, cursor);
cursor.next();
addNote(key, cursor);
}
else {
console.log("Adding note at ", i);
cursor.setDuration(1, 4);
addNote(key, cursor);
}

cursor.next();
}
score.endCmd()
var notes = realMeasures * 4; //number of 1/4th notes

for (var staff = 0; staff < 2; ++staff) { //piano has two staves to fill
cursor.track = staff * 4; //4 voice tracks per staff
cursor.rewind(0); //go to the start of the score
//add notes
for (var i = 0; i < notes; ++i) {
if (Math.random() < 0.4) {
console.log("Adding two notes at ", i);
cursor.setDuration(1, 8);
addNote(key, cursor);
addNote(key, cursor);
}
else {
console.log("Adding note at ", i);
cursor.setDuration(1, 4);
addNote(key, cursor);
}
} //done adding notes to this staff
}
score.endCmd();
Qt.quit();
}

GridLayout {
anchors.fill: parent
columns: 2
@@ -89,12 +87,13 @@ MuseScore {
}

SpinBox {
id: octaves
minimumValue: 1
maximumValue: 3
stepSize: 1
Layout.fillWidth: true
Layout.preferredHeight: 25

value: 1
}

Button {

0 comments on commit 386bb4f

Please sign in to comment.
You can’t perform that action at this time.