TAB: initial support for multiple voices.

Note fretting in one voice takes into account frets in other voices.
Stems, beams, etc are NOT adjusted yet.
This commit is contained in:
Maurizio M. Gavioli 2013-03-02 23:40:59 +01:00
parent ebb86c6e88
commit a78988d1fa
5 changed files with 24 additions and 15 deletions

View file

@ -1263,7 +1263,7 @@ void Score::upDown(bool up, UpDownMode mode)
refret = true;
}
if (refret)
tab->fretChord(oNote->chord());
tab->fretChords(oNote->chord());
}
// play new note with velocity 80 for 0.3 sec:

View file

@ -3405,10 +3405,10 @@ void Measure::updateAccidentals(Segment* segment, int staffIdx, AccidentalState*
continue;
// TAB_STAFF is different, as each note has to be fretted
// in the context of the whole chord
// in the context of the all of the chords of the whole segment
if (staffGroup == TAB_STAFF) {
instrument->tablature()->fretChord(chord);
instrument->tablature()->fretChords(chord);
continue; // skip other staff type cases
}

View file

@ -143,8 +143,8 @@ int Tablature::fret(int pitch, int string) const
}
//---------------------------------------------------------
// fretChord
// Assigns fretting to all the notes of the chord,
// fretChords
// Assigns fretting to all the notes of each chord in the same segment of chord
// re-using existing fretting wherever possible
//
// Minimizes fret conflicts (multiple notes on the same string)
@ -153,7 +153,7 @@ int Tablature::fret(int pitch, int string) const
// a separate string
//---------------------------------------------------------
void Tablature::fretChord(Chord * chord) const
void Tablature::fretChords(Chord * chord) const
{
int nFret, nNewFret, nTempFret;
int nString, nNewString, nTempString;
@ -167,16 +167,25 @@ void Tablature::fretChord(Chord * chord) const
for(nString=0; nString<strings(); nString++)
bUsed[nString] = false;
// we also need the notes sorted in order of string (from highest to lowest) and then pitch
Segment* seg = chord->segment();
QMap<int, Note *> sortedNotes;
int idx = 0;
int key;
foreach(Note * note, chord->notes()) {
key = note->string()*100000;
if(key < 0) // in case string is -1
key = -key;
key -= note->pitch() * 100 + idx; // disambiguate notes of equal pitch
sortedNotes.insert(key, note);
idx++;
// scan each chord of seg from same staff as 'chord', inserting each of its notes in sortedNotes
int trk;
int trkFrom = (chord->track() / VOICES) * VOICES;
int trkTo = trkFrom + VOICES;
for(trk = trkFrom; trk < trkTo; ++trk) {
Element* ch = seg->elist().at(trk);
if (ch && ch->type() == Element::CHORD)
foreach(Note * note, static_cast<Chord*>(ch)->notes()) {
key = note->string()*100000;
if(key < 0) // in case string is -1
key = -key;
key -= note->pitch() * 100 + idx; // disambiguate notes of equal pitch
sortedNotes.insert(key, note);
idx++;
}
}
// scan chord notes from highest, matching with strings from the highest

View file

@ -34,7 +34,7 @@ public:
Tablature(int numFrets, QList<int>& strings);
bool convertPitch(int pitch, int* string, int* fret) const;
int fret(int pitch, int string) const;
void fretChord(Chord * chord) const;
void fretChords(Chord * chord) const;
int getPitch(int string, int fret) const;
int strings() const { return stringTable.size(); }
QList<int> stringList() const { return stringTable; }

View file

@ -4395,7 +4395,7 @@ void ScoreView::cmdAddFret(int fret)
InputState& is = _score->inputState();
if (is.track() == -1) // invalid state
return;
if (is.segment() == 0 || is.cr() == 0) {
if (is.segment() == 0 /*|| is.cr() == 0*/) {
qDebug("cannot enter notes here (no chord rest at current position)");
return;
}