more accessible fret diagrams

This commit is contained in:
ws 2015-11-02 11:20:40 +01:00
parent d45cc192e5
commit 60cb031bb0
15 changed files with 416 additions and 64 deletions

View file

@ -72,10 +72,10 @@ class Cursor : public QObject {
Cursor(Score* c = 0);
Cursor(Score*, bool);
Score* score() const { return _score; }
Score* score() const { return _score; }
void setScore(Score* s);
int track() const { return _track; }
int track() const { return _track; }
void setTrack(int v);
int staffIdx() const;
@ -84,11 +84,11 @@ class Cursor : public QObject {
int voice() const;
void setVoice(int v);
int filter() const { return int(_filter); }
void setFilter(int f) { _filter = Segment::Type(f); }
int filter() const { return int(_filter); }
void setFilter(int f) { _filter = Segment::Type(f); }
Element* element() const;
Segment* segment() const { return _segment; }
Segment* segment() const { return _segment; }
Measure* measure() const;
int tick();

View file

@ -347,12 +347,9 @@ void FretDiagram::write(Xml& xml) const
xml.stag("FretDiagram");
Element::writeProperties(xml);
if (_strings != DEFAULT_STRINGS)
xml.tag("strings", _strings);
if (_frets != DEFAULT_FRETS)
xml.tag("frets", _frets);
if (_fretOffset)
xml.tag("fretOffset", _fretOffset);
writeProperty(xml, P_ID::FRET_STRINGS);
writeProperty(xml, P_ID::FRET_FRETS);
writeProperty(xml, P_ID::FRET_OFFSET);
for (int i = 0; i < _strings; ++i) {
if ((_dots && _dots[i]) || (_marker && _marker[i]) || (_fingering && _fingering[i])) {
xml.stag(QString("string no=\"%1\"").arg(i));
@ -365,8 +362,7 @@ void FretDiagram::write(Xml& xml) const
xml.etag();
}
}
if (_barre)
xml.tag("barre", _barre);
writeProperty(xml, P_ID::FRET_BARRE);
writeProperty(xml, P_ID::MAG);
if (_harmony)
_harmony->write(xml);
@ -607,8 +603,8 @@ void FretDiagram::writeMusicXML(Xml& xml) const
xml.tag("string", strings() - i);
xml.tag("fret", _dots[i]);
xml.etag();
}
}
}
qDebug("FretDiagram::writeMusicXML() this %p dots %s marker %s fingering %s",
this, qPrintable(strDots), qPrintable(strMarker), qPrintable(strFingering));
/*
@ -620,6 +616,51 @@ void FretDiagram::writeMusicXML(Xml& xml) const
xml.etag();
}
//---------------------------------------------------------
// undoSetUserMag
//---------------------------------------------------------
void FretDiagram::undoSetUserMag(qreal val)
{
score()->undoChangeProperty(this, P_ID::MAG, val);
}
//---------------------------------------------------------
// undoSetStrings
//---------------------------------------------------------
void FretDiagram::undoSetStrings(int val)
{
score()->undoChangeProperty(this, P_ID::FRET_STRINGS, val);
}
//---------------------------------------------------------
// undoSetFrets
//---------------------------------------------------------
void FretDiagram::undoSetFrets(int val)
{
score()->undoChangeProperty(this, P_ID::FRET_FRETS, val);
}
//---------------------------------------------------------
// undoSetBarre
//---------------------------------------------------------
void FretDiagram::undoSetBarre(int val)
{
score()->undoChangeProperty(this, P_ID::FRET_BARRE, val);
}
//---------------------------------------------------------
// undoSetFretOffset
//---------------------------------------------------------
void FretDiagram::undoSetFretOffset(int val)
{
score()->undoChangeProperty(this, P_ID::FRET_OFFSET, val);
}
//---------------------------------------------------------
// getProperty
//---------------------------------------------------------
@ -628,6 +669,10 @@ QVariant FretDiagram::getProperty(P_ID propertyId) const
{
switch (propertyId) {
case P_ID::MAG: return userMag();
case P_ID::FRET_STRINGS: return strings();
case P_ID::FRET_FRETS: return frets();
case P_ID::FRET_BARRE: return barre();
case P_ID::FRET_OFFSET: return fretOffset();
default:
return Element::getProperty(propertyId);
}
@ -641,6 +686,10 @@ QVariant FretDiagram::propertyDefault(P_ID propertyId) const
{
switch (propertyId) {
case P_ID::MAG: return 1.0;
case P_ID::FRET_STRINGS: return DEFAULT_STRINGS;
case P_ID::FRET_FRETS: return DEFAULT_FRETS;
case P_ID::FRET_BARRE: return 0;
case P_ID::FRET_OFFSET: return 0;
default:
return Element::propertyDefault(propertyId);
}
@ -656,9 +705,22 @@ bool FretDiagram::setProperty(P_ID propertyId, const QVariant& v)
case P_ID::MAG:
setUserMag(v.toDouble());
break;
case P_ID::FRET_STRINGS:
setStrings(v.toInt());
break;
case P_ID::FRET_FRETS:
setFrets(v.toInt());
break;
case P_ID::FRET_BARRE:
setBarre(v.toInt());
break;
case P_ID::FRET_OFFSET:
setOffset(v.toInt());
break;
default:
return Element::setProperty(propertyId, v);
}
score()->setLayoutAll(true);
return true;
}

View file

@ -27,11 +27,35 @@ static const int DEFAULT_FRETS = 5;
//---------------------------------------------------------
// @@ FretDiagram
/// Fretboard diagram
//
// @P userMag qreal
// @P strings int number of strings
// @P frets int number of frets
// @P barre int barre
// @P fretOffset int
//---------------------------------------------------------
class FretDiagram : public Element {
#ifdef SCRIPT_INTERFACE
Q_OBJECT
Q_PROPERTY(qreal userMag READ userMag WRITE undoSetUserMag)
Q_PROPERTY(int strings READ strings WRITE undoSetStrings)
Q_PROPERTY(int frets READ frets WRITE undoSetFrets)
Q_PROPERTY(int barre READ barre WRITE undoSetBarre)
Q_PROPERTY(int fretOffset READ fretOffset WRITE undoSetFretOffset)
public:
void undoSetUserMag(qreal val);
void undoSetStrings(int val);
void undoSetFrets(int val);
void undoSetBarre(int val);
void undoSetFretOffset(int val);
private:
#endif
int _strings { DEFAULT_STRINGS };
int maxStrings { 0 };
int _frets { DEFAULT_FRETS };

View file

@ -232,6 +232,11 @@ static const PropertyData propertyList[] = {
{ P_ID::LAYOUT_MODE, false, 0, P_TYPE::INT },
{ P_ID::FRET_STRINGS, false, "strings", P_TYPE::INT },
{ P_ID::FRET_FRETS, false, "frets", P_TYPE::INT },
{ P_ID::FRET_BARRE, false, "barre", P_TYPE::INT },
{ P_ID::FRET_OFFSET, false, "fretOffset", P_TYPE::INT },
{ P_ID::END, false, "", P_TYPE::INT }
};

View file

@ -226,6 +226,11 @@ enum class P_ID : unsigned char {
LAYOUT_MODE,
FRET_STRINGS,
FRET_FRETS,
FRET_BARRE,
FRET_OFFSET,
END
};
@ -257,7 +262,7 @@ enum class P_TYPE : char {
SYMID,
TEXT_STYLE,
INT_LIST,
GLISSANDO_STYLE
GLISSANDO_STYLE,
};
extern QVariant getProperty(P_ID type, XmlReader& e);

View file

@ -240,7 +240,7 @@ void Inspector::setElements(const QList<Element*>& l)
ie = new InspectorAmbitus(this);
break;
case Element::Type::FRET_DIAGRAM:
ie = new InspectorFret(this);
ie = new InspectorFretDiagram(this);
break;
case Element::Type::LAYOUT_BREAK:
ie = new InspectorBreak(this);

View file

@ -39,6 +39,7 @@
#include "ui_inspector_slur.h"
#include "ui_inspector_empty.h"
#include "ui_inspector_text.h"
#include "ui_inspector_fret.h"
namespace Ms {

View file

@ -18,10 +18,10 @@
namespace Ms {
//---------------------------------------------------------
// InspectorFret
// InspectorFretDiagram
//---------------------------------------------------------
InspectorFret::InspectorFret(QWidget* parent)
InspectorFretDiagram::InspectorFretDiagram(QWidget* parent)
: InspectorBase(parent)
{
e.setupUi(addWidget());
@ -33,6 +33,9 @@ InspectorFret::InspectorFret(QWidget* parent)
{ P_ID::USER_OFF, 0, 0, e.offsetX, e.resetX },
{ P_ID::USER_OFF, 1, 0, e.offsetY, e.resetY },
{ P_ID::MAG, 0, 0, f.mag, f.resetMag },
{ P_ID::FRET_STRINGS, 0, 0, f.strings, f.resetStrings },
{ P_ID::FRET_FRETS, 0, 0, f.frets, f.resetFrets },
{ P_ID::FRET_BARRE, 0, 0, f.barre, f.resetBarre }
};
mapSignals();

View file

@ -20,17 +20,17 @@
namespace Ms {
//---------------------------------------------------------
// InspectorFret
// InspectorFretDiagram
//---------------------------------------------------------
class InspectorFret : public InspectorBase {
class InspectorFretDiagram : public InspectorBase {
Q_OBJECT
UiInspectorElement e;
Ui::InspectorFret f;
Ui::InspectorFretDiagram f;
public:
InspectorFret(QWidget* parent);
InspectorFretDiagram(QWidget* parent);
};

View file

@ -1,25 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>InspectorFret</class>
<widget class="QWidget" name="InspectorFret">
<class>InspectorFretDiagram</class>
<widget class="QWidget" name="InspectorFretDiagram">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>252</width>
<height>110</height>
<width>329</width>
<height>141</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Expanding" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string/>
</property>
<property name="accessibleName">
<string>Ottava Inspector</string>
<string>Element Inspector</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="spacing">
<number>0</number>
</property>
<property name="sizeConstraint">
<enum>QLayout::SetNoConstraint</enum>
</property>
<property name="leftMargin">
<number>0</number>
</property>
@ -41,26 +50,13 @@
</font>
</property>
<property name="text">
<string>Fretboard Diagram</string>
<string>FretDiagram</string>
</property>
<property name="alignment">
<set>Qt::AlignCenter</set>
</property>
</widget>
</item>
<item>
<widget class="QFrame" name="frame">
<property name="frameShape">
<enum>QFrame::HLine</enum>
</property>
<property name="frameShadow">
<enum>QFrame::Raised</enum>
</property>
<property name="lineWidth">
<number>2</number>
</property>
</widget>
</item>
<item>
<layout class="QGridLayout" name="gridLayout">
<property name="leftMargin">
@ -75,6 +71,9 @@
<property name="verticalSpacing">
<number>0</number>
</property>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="mag"/>
</item>
<item row="0" column="0">
<widget class="QLabel" name="label">
<property name="text">
@ -82,32 +81,73 @@
</property>
</widget>
</item>
<item row="0" column="3">
<item row="0" column="2">
<widget class="QToolButton" name="resetMag">
<property name="toolTip">
<string>Reset value</string>
</property>
<property name="accessibleName">
<string>Reset Type value</string>
<string>Reset Size in staff space units value</string>
</property>
<property name="text">
<string notr="true">...</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="mag">
<property name="minimum">
<double>0.100000000000000</double>
<item row="3" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>barre</string>
</property>
<property name="maximum">
<double>10.000000000000000</double>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>strings</string>
</property>
<property name="singleStep">
<double>0.200000000000000</double>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>frets</string>
</property>
<property name="value">
<double>1.000000000000000</double>
</widget>
</item>
<item row="3" column="1">
<widget class="QSpinBox" name="barre"/>
</item>
<item row="1" column="1">
<widget class="QSpinBox" name="strings"/>
</item>
<item row="2" column="1">
<widget class="QSpinBox" name="frets"/>
</item>
<item row="1" column="2">
<widget class="QToolButton" name="resetStrings">
<property name="accessibleName">
<string>Reset Size in staff space units value</string>
</property>
<property name="text">
<string notr="true">...</string>
</property>
</widget>
</item>
<item row="2" column="2">
<widget class="QToolButton" name="resetFrets">
<property name="accessibleName">
<string>Reset Size in staff space units value</string>
</property>
<property name="text">
<string notr="true">...</string>
</property>
</widget>
</item>
<item row="3" column="2">
<widget class="QToolButton" name="resetBarre">
<property name="accessibleName">
<string>Reset Size in staff space units value</string>
</property>
<property name="text">
<string notr="true">...</string>
</property>
</widget>
</item>
@ -115,9 +155,8 @@
</item>
</layout>
</widget>
<tabstops>
<tabstop>resetMag</tabstop>
</tabstops>
<resources/>
<resources>
<include location="../musescore.qrc"/>
</resources>
<connections/>
</ui>

View file

@ -0,0 +1,8 @@
test script p2
FretDiagram
userMag:1
strings:6
frets:5
barre:0
fretOffset:0
set userMag:2.2

38
mtest/scripting/p2.qml Normal file
View file

@ -0,0 +1,38 @@
import QtQuick 2.0
import MuseScore 1.0
MuseScore {
menuPath: "Plugins.p2"
onRun: {
openLog("p2.log");
logn("test script p2")
var cursor = curScore.newCursor();
cursor.voice = 0;
cursor.staffIdx = 0;
cursor.filter = -1;
cursor.rewind(0);
while (cursor.segment) {
var a = cursor.segment.annotations;
var l = a.length;
for (var i = 0; i < l; i++) {
var e = a[i];
logn(e._name());
var type = e.type;
if (type == Element.FRET_DIAGRAM) {
log2("userMag:", e.userMag)
log2("strings:", e.strings)
log2("frets:", e.frets)
log2("barre:", e.barre)
log2("fretOffset:", e.fretOffset)
e.userMag = 2.2;
log2("set userMag:", e.userMag)
}
}
cursor.next();
}
closeLog();
Qt.quit()
}
}

165
mtest/scripting/s2.mscx Normal file
View file

@ -0,0 +1,165 @@
<?xml version="1.0" encoding="UTF-8"?>
<museScore version="2.07">
<programVersion>2.1.0</programVersion>
<programRevision>3543170</programRevision>
<Score>
<LayerTag id="0" tag="default"></LayerTag>
<currentLayer>0</currentLayer>
<Synthesizer>
</Synthesizer>
<Division>480</Division>
<Style>
<lastSystemFillLimit>0</lastSystemFillLimit>
<page-layout>
<page-height>1683.36</page-height>
<page-width>1190.88</page-width>
<page-margins type="even">
<left-margin>56.6929</left-margin>
<right-margin>56.6929</right-margin>
<top-margin>56.6929</top-margin>
<bottom-margin>113.386</bottom-margin>
</page-margins>
<page-margins type="odd">
<left-margin>56.6929</left-margin>
<right-margin>56.6929</right-margin>
<top-margin>56.6929</top-margin>
<bottom-margin>113.386</bottom-margin>
</page-margins>
</page-layout>
<Spatium>1.76389</Spatium>
</Style>
<showInvisible>1</showInvisible>
<showUnprintable>1</showUnprintable>
<showFrames>1</showFrames>
<showMargins>0</showMargins>
<metaTag name="arranger"></metaTag>
<metaTag name="composer"></metaTag>
<metaTag name="copyright"></metaTag>
<metaTag name="creationDate">2015-04-02</metaTag>
<metaTag name="lyricist"></metaTag>
<metaTag name="movementNumber"></metaTag>
<metaTag name="movementTitle"></metaTag>
<metaTag name="platform">Linux</metaTag>
<metaTag name="poet"></metaTag>
<metaTag name="source"></metaTag>
<metaTag name="translator"></metaTag>
<metaTag name="workNumber"></metaTag>
<metaTag name="workTitle">s1</metaTag>
<PageList>
<Page>
<System>
</System>
<System>
</System>
</Page>
</PageList>
<Part>
<Staff id="1">
<StaffType group="pitched">
<name>stdNormal</name>
</StaffType>
</Staff>
<trackName>Piano</trackName>
<Instrument>
<longName>Piano</longName>
<shortName>Pno.</shortName>
<trackName>Piano</trackName>
<minPitchP>21</minPitchP>
<maxPitchP>108</maxPitchP>
<minPitchA>21</minPitchA>
<maxPitchA>108</maxPitchA>
<instrumentId>keyboard.piano</instrumentId>
<clef staff="2">F</clef>
<Articulation>
<velocity>100</velocity>
<gateTime>95</gateTime>
</Articulation>
<Articulation name="staccatissimo">
<velocity>100</velocity>
<gateTime>33</gateTime>
</Articulation>
<Articulation name="staccato">
<velocity>100</velocity>
<gateTime>50</gateTime>
</Articulation>
<Articulation name="portato">
<velocity>100</velocity>
<gateTime>67</gateTime>
</Articulation>
<Articulation name="tenuto">
<velocity>100</velocity>
<gateTime>100</gateTime>
</Articulation>
<Articulation name="marcato">
<velocity>120</velocity>
<gateTime>67</gateTime>
</Articulation>
<Articulation name="sforzato">
<velocity>120</velocity>
<gateTime>100</gateTime>
</Articulation>
<Channel>
<program value="0"/>
<synti>Fluid</synti>
</Channel>
</Instrument>
</Part>
<Staff id="1">
<VBox>
<height>10</height>
<Text>
<style>Title</style>
<text>s1</text>
</Text>
</VBox>
<Measure number="1">
<TimeSig>
<sigN>4</sigN>
<sigD>4</sigD>
<showCourtesySig>1</showCourtesySig>
</TimeSig>
<FretDiagram>
<string no="0">
<marker>88</marker>
</string>
<string no="1">
<dot>3</dot>
</string>
<string no="2">
<dot>2</dot>
</string>
<string no="3">
<marker>79</marker>
</string>
<string no="4">
<dot>1</dot>
</string>
<string no="5">
<marker>79</marker>
</string>
</FretDiagram>
<Chord>
<durationType>quarter</durationType>
<Note>
<pitch>67</pitch>
<tpc>15</tpc>
</Note>
</Chord>
<Rest>
<durationType>quarter</durationType>
</Rest>
<Chord>
<durationType>half</durationType>
<Note>
<pitch>69</pitch>
<tpc>17</tpc>
</Note>
</Chord>
<BarLine>
<subtype>end</subtype>
<span>1</span>
</BarLine>
</Measure>
</Staff>
</Score>
</museScore>

View file

@ -30,11 +30,12 @@ class TestScripting : public QObject, public MTest
{
Q_OBJECT
void read1(const char*, const char*);
void read1(const QString&, const QString&);
private slots:
void initTestCase();
void test1() { read1("s1", "p1"); }
void test1() { read1("s1", "p1"); } // scan note rest
void test2() { read1("s2", "p2"); } // scan segment attributes
};
//---------------------------------------------------------
@ -53,7 +54,7 @@ void TestScripting::initTestCase()
// reference
//---------------------------------------------------------
void TestScripting::read1(const char* file, const char* script)
void TestScripting::read1(const QString& file, const QString& script)
{
Score* score = readScore(DIR + file + ".mscx");
MuseScoreCore::mscoreCore->setCurrentScore(score);
@ -83,7 +84,7 @@ void TestScripting::read1(const char* file, const char* script)
QmlPlugin* item = qobject_cast<QmlPlugin*>(obj);
item->runPlugin();
QVERIFY(compareFiles("p1.log", DIR + "p1.log.ref"));
QVERIFY(compareFiles(script + ".log", DIR + script + ".log.ref"));
delete score;
}

View file

@ -4,3 +4,4 @@ P=../../build.debug
#P=../../../../MuseScore-build
cp $P/mtest/scripting/p1.log p1.log.ref
cp $P/mtest/scripting/p2.log p2.log.ref