Skip to content

Commit

Permalink
Implementation for issue humdrum-tools/verovio-humdrum-viewer#830
Browse files Browse the repository at this point in the history
  • Loading branch information
craigsapp committed Aug 17, 2023
1 parent ffd96fd commit fdf0413
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 24 deletions.
3 changes: 3 additions & 0 deletions include/vrv/iohumdrum.h
Original file line number Diff line number Diff line change
Expand Up @@ -834,6 +834,9 @@ class HumdrumInput : public vrv::Input {
bool isNotAtStartOfMeasure(std::vector<hum::HTp> &layerdata, int index);
void analyzeFingerings(hum::HumdrumFile &infile);
void analyzeFingerings(hum::HTp sstart);
void insertMidMeasureKeySignature(
int staffindex, std::vector<std::string> &elements, std::vector<void *> &pointers, hum::HTp token);
int getKeySignatureNumber(const std::string &humkeysig);

// header related functions: ///////////////////////////////////////////
void createHeader();
Expand Down
115 changes: 91 additions & 24 deletions src/iohumdrum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6904,30 +6904,12 @@ hum::HTp HumdrumInput::getVisualKeySignature(hum::HTp keysigtok)

//////////////////////////////
//
// HumdrumInput::setKeySig -- Convert a Humdrum keysig to an MEI keysig.
// If there is a visual key sig, such as "*vk[f#]" within the same timestamp
// (in the same spine), then display that instead with @type="visual-key-signature".
// HumdrumInput::getKeySignatureNumber -- Example *k[f#c#] => +2
//

template <class ELEMENT>
void HumdrumInput::setKeySig(
int staffindex, ELEMENT element, const std::string &keysig, hum::HTp keysigtok, hum::HTp keytok, bool secondary)
int HumdrumInput::getKeySignatureNumber(const std::string &humkeysig)
{

std::string ks;
hum::HTp zkeysigtok;
hum::HTp vkeysigtok = getVisualKeySignature(keysigtok);
bool visualType;
if (vkeysigtok) {
zkeysigtok = vkeysigtok;
ks = *zkeysigtok;
visualType = true;
}
else {
zkeysigtok = keysigtok;
ks = keysig;
visualType = false;
}
std::string ks = humkeysig;

auto pos = ks.find("]");
if (pos != std::string::npos) {
Expand Down Expand Up @@ -6985,6 +6967,89 @@ void HumdrumInput::setKeySig(
keynum = +7;
}

return keynum;
}

//////////////////////////////
//
// insertMidMeasureKeySignature --
//

void HumdrumInput::insertMidMeasureKeySignature(
int staffindex, std::vector<std::string> &elements, std::vector<void *> &pointers, hum::HTp token)
{
KeySig *keysig = new KeySig();
appendElement(elements, pointers, keysig);
setLocationId(keysig, token);
keysig->SetType("mid-measure");

int keynum = getKeySignatureNumber(*token);
int fifthsAdjust = 0;
if (staffindex >= 0) {
fifthsAdjust = hum::Convert::base40IntervalToLineOfFifths(m_transpose[staffindex]);
}
keynum += fifthsAdjust;
int keyvalue = keynum;

if ((keyvalue >= -7) && (keyvalue <= +7)) {
// standard key signature
if (keyvalue < 0) {
keysig->SetSig(std::make_pair(-keyvalue, ACCIDENTAL_WRITTEN_f));
}
else if (keyvalue > 0) {
keysig->SetSig(std::make_pair(keyvalue, ACCIDENTAL_WRITTEN_s));
}
else if (keyvalue == 0) {
keysig->SetSig(std::make_pair(keyvalue, ACCIDENTAL_WRITTEN_NONE));
}
else {
keysig->SetSig(std::make_pair(-1, ACCIDENTAL_WRITTEN_NONE));
}
}
else {
// Non-standard keysignature, so give a NONE style (deal with it later).
}

bool secondary = true;
if (secondary && (keyvalue == 0)) {
// Force cancellation keysignature when there are no
// sharps/flats in key signature change.
keysig->SetCancelaccid(CANCELACCID_before);
}
else if (m_show_cautionary_keysig) {
keysig->SetCancelaccid(CANCELACCID_before);
}
}

//////////////////////////////
//
// HumdrumInput::setKeySig -- Convert a Humdrum keysig to an MEI keysig.
// If there is a visual key sig, such as "*vk[f#]" within the same timestamp
// (in the same spine), then display that instead with @type="visual-key-signature".
//

template <class ELEMENT>
void HumdrumInput::setKeySig(
int staffindex, ELEMENT element, const std::string &keysig, hum::HTp keysigtok, hum::HTp keytok, bool secondary)
{

std::string ks;
hum::HTp zkeysigtok;
hum::HTp vkeysigtok = getVisualKeySignature(keysigtok);
bool visualType;
if (vkeysigtok) {
zkeysigtok = vkeysigtok;
ks = *zkeysigtok;
visualType = true;
}
else {
zkeysigtok = keysigtok;
ks = keysig;
visualType = false;
}

int keynum = getKeySignatureNumber(ks);

int fifthsAdjust = 0;
if (staffindex >= 0) {
fifthsAdjust = hum::Convert::base40IntervalToLineOfFifths(m_transpose[staffindex]);
Expand Down Expand Up @@ -7780,12 +7845,9 @@ void HumdrumInput::storeStaffLayerTokensForMeasure(int startline, int endline)
lt[staffindex][layerindex].push_back(token);

if ((layerindex == 0) && (token->isClef())) {

int layercount = getCurrentLayerCount(token);

// Duplicate clef in all layers (needed for cases when
// a secondary layer ends before the end of a measure.

for (int k = layercount; k < (int)lt[staffindex].size(); k++) {
lt[staffindex][k].push_back(token);
}
Expand Down Expand Up @@ -11686,6 +11748,11 @@ bool HumdrumInput::fillContentsOfLayer(int track, int startline, int endline, in

bool notAtStart = isNotAtStartOfMeasure(layerdata, i);

bool isKeySignature = layerdata[i]->isKeySignature();
if (notAtStart && isKeySignature) {
insertMidMeasureKeySignature(staffindex, elements, pointers, token);
}

bool forceClefChange = false;
if (token->isClef() || (*token == "*")) {
if (!(token->isMensLike() && notAtStart)) {
Expand Down

0 comments on commit fdf0413

Please sign in to comment.