Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 9 additions & 10 deletions include/tool-mint.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,13 @@ class Tool_mint : public HumTool {
bool run (HumdrumFile& infile, std::ostream& out);

protected:
void initialize (void);
void processFile (HumdrumFile& infile);
void analyzeLine (HumdrumFile& infile, int line);
int processKernSpines (HumdrumFile& infile, int line, int start);
std::string getIntervalToken (HTp token);
std::string getIntervalQuality (int base40interval);
HTp getPreviousAttackToken (HTp token);
int getRepresentativeBase40Pitch(HTp token);
void initialize (void);
void processFile (HumdrumFile& infile);
std::vector<std::string> getTrackData (HTp kernstart, int lineCount);
std::string getIntervalToken (HTp token);
std::string getIntervalQuality (int base40interval);
HTp getPreviousAttackToken (HTp token);
int getRepresentativeBase40Pitch(HTp token);

private:
bool m_absoluteQ = false; // -a option: hide direction of the interval
Expand All @@ -52,8 +51,8 @@ class Tool_mint : public HumTool {
bool m_lowestQ = false; // -l option: use lowest note of a chord instead of the highest
bool m_cdataQ = false; // -x option: label the spine **cdata-mint instead of **mint

std::string m_kernTracks = ""; // used with -k option
std::string m_spineTracks = ""; // used with -s option
std::string m_kernTracks = ""; // used with -k option
std::string m_spines = ""; // used with -s option
std::vector<bool> m_selectedKernSpines; // used with -k and -s option

};
Expand Down
130 changes: 34 additions & 96 deletions min/humlib.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
// Creation Date: Sat Aug 8 12:24:49 PDT 2015
// Last Modified: Sa. 11 Juli 2026 22:39:12 CEST
// Last Modified: Fr. 24 Juli 2026 10:01:03 CEST
// Filename: min/humlib.cpp
// URL: https://github.com/craigsapp/humlib/blob/master/min/humlib.cpp
// Syntax: C++11
Expand Down Expand Up @@ -111493,7 +111493,7 @@ Tool_mint::Tool_mint(void) {
define("l|lowest=b", "use the lowest note of a chord instead of the highest note");
define("x|cdata=b", "label the spine **cdata-mint instead of **mint");
define("k|kern-tracks=s", "process only the specified kern spines");
define("s|spine-tracks|spine|spines|track|tracks=s", "process only the specified spines");
define("s|spine|spines=s", "process only the specified spines");
}


Expand Down Expand Up @@ -111552,8 +111552,8 @@ void Tool_mint::initialize(void) {
m_lowestQ = getBoolean("lowest");
m_cdataQ = getBoolean("cdata");

if (getBoolean("spine-tracks")) {
m_spineTracks = getString("spine-tracks");
if (getBoolean("spines")) {
m_spines = getString("spines");
} else if (getBoolean("kern-tracks")) {
m_kernTracks = getString("kern-tracks");
}
Expand All @@ -111574,9 +111574,10 @@ void Tool_mint::processFile(HumdrumFile& infile) {
m_selectedKernSpines.resize(maxTrack + 1); // +1 since track=0 is not used
fill(m_selectedKernSpines.begin(), m_selectedKernSpines.end(), true);

vector<HTp> kernspines = infile.getKernSpineStartList();

// Calculate which input spines to process based on -k or -s option:
if (!m_kernTracks.empty()) {
vector<HTp> kernspines = infile.getKernSpineStartList();
vector<int> ktracks = Convert::extractIntegerList(m_kernTracks, maxTrack);
fill(m_selectedKernSpines.begin(), m_selectedKernSpines.end(), false);
for (int i = 0; i < (int)ktracks.size(); i++) {
Expand All @@ -111587,114 +111588,51 @@ void Tool_mint::processFile(HumdrumFile& infile) {
int track = kernspines.at(index)->getTrack();
m_selectedKernSpines.at(track) = true;
}
} else if (!m_spineTracks.empty()) {
} else if (!m_spines.empty()) {
fill(m_selectedKernSpines.begin(), m_selectedKernSpines.end(), false);
infile.makeBooleanTrackList(m_selectedKernSpines, m_spineTracks);
}

for (int i = 0; i < infile.getLineCount(); i++) {
analyzeLine(infile, i);
infile.makeBooleanTrackList(m_selectedKernSpines, m_spines);
}
}



//////////////////////////////
//
// Tool_mint::analyzeLine -- Append a **mint spine after every processed
// **kern spine on the current line.
//
string exinterp = m_cdataQ ? "**cdata-mint" : "**mint";
int lineCount = infile.getLineCount();

void Tool_mint::analyzeLine(HumdrumFile& infile, int line) {
if (!infile[line].hasSpines()) {
m_humdrum_text << infile[line] << "\n";
return;
}
for (int i = 0; i < infile[line].getFieldCount(); i++) {
HTp token = infile.token(line, i);
if (!token->isKern() || !m_selectedKernSpines.at(token->getTrack())) {
m_humdrum_text << token;
if (i < infile[line].getFieldCount() - 1) {
m_humdrum_text << '\t';
}
// Insert each voice's spine right after its own track, processing from
// last to first so that earlier (not-yet-processed) voices' track
// numbers are not shifted by a later insertion.
for (int i = (int)kernspines.size() - 1; i >= 0; i--) {
int track = kernspines[i]->getTrack();
if (!m_selectedKernSpines.at(track)) {
continue;
}
i = processKernSpines(infile, line, i);
if (i < infile[line].getFieldCount() - 1) {
m_humdrum_text << '\t';
}
vector<string> trackData = getTrackData(kernspines[i], lineCount);
infile.insertDataSpineAfter(track, trackData, ".", exinterp);
}
m_humdrum_text << '\n';
infile.createLinesFromTokens();

// Enables usage in verovio (`!!!filter: mint`)
m_humdrum_text << infile;
}



//////////////////////////////
//
// Tool_mint::processKernSpines -- Print the tokens of a **kern spine
// (including any of its subspines) followed by the matching **mint
// analysis tokens. Returns the field index of the last token that
// was processed on the line.
// Tool_mint::getTrackData -- Calculate the **mint spine data for a single
// **kern spine, one entry per line of the file (empty for non-data
// lines, which are filled in automatically by appendDataSpine/
// insertDataSpineBefore).
//

int Tool_mint::processKernSpines(HumdrumFile& infile, int line, int start) {
HTp token = infile.token(line, start);
int track = token->getTrack();
vector<HTp> toks;
toks.push_back(token);
for (int i = start + 1; i < infile[line].getFieldCount(); i++) {
HTp newtok = infile.token(line, i);
if (newtok->getTrack() == track) {
toks.push_back(newtok);
continue;
}
break;
}

int toksize = (int)toks.size();

// print the **kern fields
for (int i = 0; i < toksize; i++) {
m_humdrum_text << toks[i];
m_humdrum_text << '\t';
}

// print the parallel **mint analysis fields
if (infile[line].isData()) {
for (int i = 0; i < toksize; i++) {
m_humdrum_text << getIntervalToken(toks[i]);
if (i < toksize - 1) {
m_humdrum_text << '\t';
}
}
} else if (infile[line].isLocalComment()) {
for (int i = 0; i < toksize; i++) {
m_humdrum_text << "!";
if (i < toksize - 1) {
m_humdrum_text << '\t';
}
}
} else if (infile[line].isInterpretation()) {
for (int i = 0; i < toksize; i++) {
if (toks[i]->compare(0, 2, "**") == 0) {
m_humdrum_text << (m_cdataQ ? "**cdata-mint" : "**mint");
} else {
m_humdrum_text << toks[i];
}
if (i < toksize - 1) {
m_humdrum_text << '\t';
}
}
} else if (infile[line].isBarline()) {
for (int i = 0; i < toksize; i++) {
m_humdrum_text << toks[0];
if (i < toksize - 1) {
m_humdrum_text << '\t';
}
vector<string> Tool_mint::getTrackData(HTp kernstart, int lineCount) {
vector<string> trackData(lineCount);
HTp current = kernstart;
while (current) {
if (current->isData()) {
trackData[current->getLineIndex()] = getIntervalToken(current);
}
current = current->getNextToken();
}

return start + toksize - 1;
return trackData;
}


Expand Down
21 changes: 10 additions & 11 deletions min/humlib.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Programmer: Craig Stuart Sapp <craig@ccrma.stanford.edu>
// Creation Date: Sat Aug 8 12:24:49 PDT 2015
// Last Modified: Sa. 11 Juli 2026 22:39:12 CEST
// Last Modified: Fr. 24 Juli 2026 10:01:03 CEST
// Filename: min/humlib.h
// URL: https://github.com/craigsapp/humlib/blob/master/min/humlib.h
// Syntax: C++11
Expand Down Expand Up @@ -9736,14 +9736,13 @@ class Tool_mint : public HumTool {
bool run (HumdrumFile& infile, std::ostream& out);

protected:
void initialize (void);
void processFile (HumdrumFile& infile);
void analyzeLine (HumdrumFile& infile, int line);
int processKernSpines (HumdrumFile& infile, int line, int start);
std::string getIntervalToken (HTp token);
std::string getIntervalQuality (int base40interval);
HTp getPreviousAttackToken (HTp token);
int getRepresentativeBase40Pitch(HTp token);
void initialize (void);
void processFile (HumdrumFile& infile);
std::vector<std::string> getTrackData (HTp kernstart, int lineCount);
std::string getIntervalToken (HTp token);
std::string getIntervalQuality (int base40interval);
HTp getPreviousAttackToken (HTp token);
int getRepresentativeBase40Pitch(HTp token);

private:
bool m_absoluteQ = false; // -a option: hide direction of the interval
Expand All @@ -9752,8 +9751,8 @@ class Tool_mint : public HumTool {
bool m_lowestQ = false; // -l option: use lowest note of a chord instead of the highest
bool m_cdataQ = false; // -x option: label the spine **cdata-mint instead of **mint

std::string m_kernTracks = ""; // used with -k option
std::string m_spineTracks = ""; // used with -s option
std::string m_kernTracks = ""; // used with -k option
std::string m_spines = ""; // used with -s option
std::vector<bool> m_selectedKernSpines; // used with -k and -s option

};
Expand Down
Loading