Skip to content

Commit

Permalink
* Note: Add GetChromaticAlteration function
Browse files Browse the repository at this point in the history
  • Loading branch information
earboxer committed Dec 6, 2019
1 parent 02025b5 commit aa04cc7
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 28 deletions.
5 changes: 5 additions & 0 deletions include/vrv/note.h
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,11 @@ class Note : public LayerElement,
char GetMIDIPitch();
///@}

/**
* Get the pitch difference in semitones of the accidental (implicit or explicit) for this note.
*/
int GetChromaticAlteration();

//----------//
// Functors //
//----------//
Expand Down
62 changes: 34 additions & 28 deletions src/note.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,39 @@ char Note::GetMIDIPitch()
return m_MIDIPitch;
}

int Note::GetChromaticAlteration()
{
Accid *accid = this->GetDrawingAccid();

if (accid && accid->HasAccidGes()) {
data_ACCIDENTAL_GESTURAL accImp = accid->GetAccidGes();
switch (accImp) {
case ACCIDENTAL_GESTURAL_s: return 1;
case ACCIDENTAL_GESTURAL_f: return -1;
case ACCIDENTAL_GESTURAL_ss: return 2;
case ACCIDENTAL_GESTURAL_ff: return -2;
default: break;
}
}
else if (accid) {
data_ACCIDENTAL_WRITTEN accExp = accid->GetAccid();
switch (accExp) {
case ACCIDENTAL_WRITTEN_s: return 1;
case ACCIDENTAL_WRITTEN_f: return -1;
case ACCIDENTAL_WRITTEN_ss: return 2;
case ACCIDENTAL_WRITTEN_x: return 2;
case ACCIDENTAL_WRITTEN_ff: return -2;
case ACCIDENTAL_WRITTEN_xs: return 3;
case ACCIDENTAL_WRITTEN_ts: return 3;
case ACCIDENTAL_WRITTEN_tf: return -3;
case ACCIDENTAL_WRITTEN_nf: return -1;
case ACCIDENTAL_WRITTEN_ns: return 1;
default: break;
}
}
return 0;
}

//----------------------------------------------------------------------------
// Functors methods
//----------------------------------------------------------------------------
Expand Down Expand Up @@ -879,8 +912,6 @@ int Note::GenerateMIDI(FunctorParams *functorParams)
return FUNCTOR_SIBLINGS;
}

Accid *accid = note->GetDrawingAccid();

// Create midi this
int midiBase = 0;
data_PITCHNAME pname = note->GetPname();
Expand All @@ -895,32 +926,7 @@ int Note::GenerateMIDI(FunctorParams *functorParams)
case PITCHNAME_NONE: break;
}
// Check for accidentals
if (accid && accid->HasAccidGes()) {
data_ACCIDENTAL_GESTURAL accImp = accid->GetAccidGes();
switch (accImp) {
case ACCIDENTAL_GESTURAL_s: midiBase += 1; break;
case ACCIDENTAL_GESTURAL_f: midiBase -= 1; break;
case ACCIDENTAL_GESTURAL_ss: midiBase += 2; break;
case ACCIDENTAL_GESTURAL_ff: midiBase -= 2; break;
default: break;
}
}
else if (accid) {
data_ACCIDENTAL_WRITTEN accExp = accid->GetAccid();
switch (accExp) {
case ACCIDENTAL_WRITTEN_s: midiBase += 1; break;
case ACCIDENTAL_WRITTEN_f: midiBase -= 1; break;
case ACCIDENTAL_WRITTEN_ss: midiBase += 2; break;
case ACCIDENTAL_WRITTEN_x: midiBase += 2; break;
case ACCIDENTAL_WRITTEN_ff: midiBase -= 2; break;
case ACCIDENTAL_WRITTEN_xs: midiBase += 3; break;
case ACCIDENTAL_WRITTEN_ts: midiBase += 3; break;
case ACCIDENTAL_WRITTEN_tf: midiBase -= 3; break;
case ACCIDENTAL_WRITTEN_nf: midiBase -= 1; break;
case ACCIDENTAL_WRITTEN_ns: midiBase += 1; break;
default: break;
}
}
midiBase += note->GetChromaticAlteration();

// Adjustment for transposition intruments
midiBase += params->m_transSemi;
Expand Down

0 comments on commit aa04cc7

Please sign in to comment.