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
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ set(SRCS
src/tool-msearch.cpp
src/tool-musicxml2hum.cpp
src/tool-myank.cpp
src/tool-notemark.cpp
src/tool-recip.cpp
src/tool-restfill.cpp
src/tool-ruthfix.cpp
Expand Down Expand Up @@ -159,6 +160,7 @@ set(HDRS
include/tool-msearch.h
include/tool-musicxml2hum.h
include/tool-myank.h
include/tool-notemark.h
include/tool-recip.h
include/tool-restfill.h
include/tool-ruthfix.h
Expand Down
11 changes: 10 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -1191,7 +1191,7 @@ tool-filter.o: tool-filter.cpp tool-filter.h \
GridPart.h GridStaff.h GridSide.h \
GridVoice.h tool-melisma.h tool-mens2kern.h \
tool-meter.h tool-metlev.h tool-modori.h \
tool-msearch.h Convert.h tool-myank.h \
tool-msearch.h Convert.h tool-myank.h tool-notemark.h \
tool-nproof.h tool-ordergps.h tool-phrase.h \
tool-pline.h tool-recip.h tool-restfill.h \
tool-rid.h tool-sab2gs.h tool-satb2gs.h \
Expand Down Expand Up @@ -1464,6 +1464,15 @@ tool-myank.o: tool-myank.cpp tool-myank.h HumTool.h \
HumParamSet.h HumdrumFileStream.h HumRegex.h \
Convert.h

tool-notemark.o: tool-notemark.cpp tool-notemark.h HumTool.h \
Options.h HumdrumFileSet.h HumdrumFile.h \
HumdrumFileContent.h HumdrumFileStructure.h \
HumdrumFileBase.h HumSignifiers.h \
HumSignifier.h HumdrumLine.h HumdrumToken.h \
HumNum.h HumAddress.h HumHash.h \
HumParamSet.h HumdrumFileStream.h NoteGrid.h \
NoteCell.h Convert.h HumRegex.h

tool-nproof.o: tool-nproof.cpp tool-nproof.h \
HumTool.h Options.h HumdrumFileSet.h \
HumdrumFile.h HumdrumFileContent.h \
Expand Down
17 changes: 17 additions & 0 deletions cli/notemark.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//
// Programmer: Wolfgang Drescher <drescher.wolfgang@gmail.com>
// Creation Date: Mon Oct 14 19:24:00 UTC 2024
// Filename: cli/notemark.cpp
// URL: https://github.com/craigsapp/humlib/blob/master/cli/notemark.cpp
// Syntax: C++11
// vim: ts=3 noexpandtab nowrap
//
// Description: Adds note markers for specific lines and voices
//

#include "humlib.h"

STREAM_INTERFACE(Tool_notemark)



60 changes: 60 additions & 0 deletions include/tool-notemark.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//
// Programmer: Wolfgang Drescher <drescher.wolfgang@gmail.com>
// Creation Date: Mon Oct 14 19:24:00 UTC 2024
// Filename: tool-notemark.h
// URL: https://github.com/craigsapp/humlib/blob/master/include/tool-notemark.h
// Syntax: C++11; humlib
// vim: syntax=cpp ts=3 noexpandtab nowrap
//
// Description: Interface for notemark tool
//

#ifndef _TOOL_NOTEMARK_H
#define _TOOL_NOTEMARK_H

#include "HumTool.h"
#include "HumdrumFile.h"

using namespace std;

namespace hum {

// START_MERGE

class Tool_notemark : public HumTool {

public:
Tool_notemark (void);
~Tool_notemark() {};

bool run (HumdrumFileSet& infiles);
bool run (HumdrumFile& infile);
bool run (const string& indata, ostream& out);
bool run (HumdrumFile& infile, ostream& out);

protected:
void initialize (void);
void processFile (HumdrumFile& infile);
int getStartLineNumber (void);
int getEndLineNumber (void);
std::vector<int> setupSpineInfo (HumdrumFile& infile);

private:
// m_kernSpines: list of all **kern spines found in file.
std::vector<HTp> m_kernSpines;

// m_selectedKernSpines: list of only the **kern spines that will be analyzed.
std::vector<HTp> m_selectedKernSpines;

std::string m_kernTracks; // used with -s option
std::string m_spineTracks; // used with -k option
std::string m_lineRange; // used with -l option
std::string m_signifier; // used with --signifier option
std::string m_color; // used with --color option
};

// END_MERGE

} // end namespace hum

#endif /* _TOOL_NOTEMARK_H */
225 changes: 224 additions & 1 deletion 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: Do 21 Nov 2024 21:59:25 CET
// Last Modified: Do 21 Nov 2024 22:57:05 CET
// Filename: min/humlib.cpp
// URL: https://github.com/craigsapp/humlib/blob/master/min/humlib.cpp
// Syntax: C++11
Expand Down Expand Up @@ -87319,6 +87319,8 @@ bool Tool_filter::run(HumdrumFileSet& infiles) {
RUNTOOL(modori, infile, commands[i].second, status);
} else if (commands[i].first == "msearch") {
RUNTOOL(msearch, infile, commands[i].second, status);
} else if (commands[i].first == "notemark") {
RUNTOOL(notemark, infile, commands[i].second, status);
} else if (commands[i].first == "nproof") {
RUNTOOL(nproof, infile, commands[i].second, status);
} else if (commands[i].first == "ordergps") {
Expand Down Expand Up @@ -115893,6 +115895,227 @@ void Tool_myank::usage(const string& ommand) {



//////////////////////////////
//
// Tool_notemark::Tool_notemark -- Set the recognized options for the tool.
//

Tool_notemark::Tool_notemark(void) {
define("k|kern-tracks=s", "process only the specified kern spines");
define("s|spine-tracks=s", "process only the specified spines");
define("l|lines|line-range=s", "line numbers range to yank (e.g. 40-50)");
define("signifier=s", "signifier to mark the notes (default: @)");
define("color=s", "color for marked notes (default: #ef4444)");

}



//////////////////////////////
//
// Tool_notemark::run -- Do the main work of the tool.
//

bool Tool_notemark::run(HumdrumFileSet &infiles) {
bool status = true;
for (int i = 0; i < infiles.getCount(); i++) {
status &= run(infiles[i]);
}
return status;
}

bool Tool_notemark::run(const string &indata, ostream &out) {
HumdrumFile infile(indata);
bool status = run(infile);
if (hasAnyText()) {
getAllText(out);
} else {
out << infile;
}
return status;
}

bool Tool_notemark::run(HumdrumFile &infile, ostream &out) {
bool status = run(infile);
if (hasAnyText()) {
getAllText(out);
} else {
out << infile;
}
return status;
}

bool Tool_notemark::run(HumdrumFile &infile) {
initialize();
processFile(infile);
infile.createLinesFromTokens();
return true;
}



//////////////////////////////
//
// Tool_notemark::initialize --
//

void Tool_notemark::initialize(void) {
m_kernTracks = getString("kern-tracks");
m_spineTracks = getString("spine-tracks");
m_lineRange = getString("lines");
m_signifier = getBoolean("signifier") ? getString("signifier") : "@";
m_color = getBoolean("color") ? getString("color") : "#ef4444";
}



//////////////////////////////
//
// Tool_notemark::processFile --
//

void Tool_notemark::processFile(HumdrumFile& infile) {

std::vector<int> selectedSpineIndices = setupSpineInfo(infile);

bool hasMarkers = false;

if (getBoolean("lines")) {
int startLineNumber = getStartLineNumber();
int endLineNumber = getEndLineNumber();
if ((startLineNumber > endLineNumber) || (endLineNumber > infile.getLineCount())) {
// Disallow when end line number is bigger then line count or when
// start line number greather than end line number
return;
}

for (int i = startLineNumber; i <= endLineNumber; i++) {
HLp line = infile.getLine(i-1);
if (line->isData()) {
vector<HTp> tokens;
line->getTokens(tokens);
for (HTp& token : tokens) {
HTp resolvedToken = token->resolveNull();
if (resolvedToken->isNonNullData()) {
if (std::find(selectedSpineIndices.begin(), selectedSpineIndices.end(), resolvedToken->getSpineIndex()) != selectedSpineIndices.end() || selectedSpineIndices.size() == 0) {
std::string tokenText = resolvedToken->getText();
if (m_signifier.size() > tokenText.size() || tokenText.compare(tokenText.size() - m_signifier.size(), m_signifier.size(), m_signifier) != 0) {
resolvedToken->resolveNull()->setText(tokenText + m_signifier);
hasMarkers = true;
}
}
}
}
line->createLineFromTokens();
}
}
}

infile.createLinesFromTokens();

if (hasMarkers) {
infile.appendLine("!!!RDF**kern: " + m_signifier + " = marked note color=\"" + m_color + "\"");
}

m_humdrum_text << infile;

}



////////////////////////
//
// Tool_notemark::getStartLineNumber -- Get start line number from --lines
//

int Tool_notemark::getStartLineNumber(void) {
HumRegex hre;
if (hre.search(m_lineRange, "^(\\d+)\\-(\\d+)$")) {
return hre.getMatchInt(1);
}
if (hre.search(m_lineRange, "^(\\d+)$")) {
return hre.getMatchInt(1);
}
return -1;
}



////////////////////////
//
// Tool_notemark::getEndLineNumber -- Get end line number from --lines
//

int Tool_notemark::getEndLineNumber(void) {
HumRegex hre;
if (hre.search(m_lineRange, "^(\\d+)\\-(\\d+)$")) {
return hre.getMatchInt(2);
}
if (hre.search(m_lineRange, "^(\\d+)$")) {
return hre.getMatchInt(1);
}
return -1;
}



//////////////////////////////
//
// Tool_notemark::setupSpineInfo --
//

std::vector<int> Tool_notemark::setupSpineInfo(HumdrumFile& infile) {

infile.getKernSpineStartList(m_kernSpines);

m_selectedKernSpines.clear();

if (!m_kernTracks.empty()) {
vector<int> tracks = Convert::extractIntegerList(m_kernTracks, (int)m_kernSpines.size());
// don't allow out-of-sequence values for the tracks list:
sort(tracks.begin(),tracks.end());
tracks.erase(unique(tracks.begin(), tracks.end()), tracks.end());
for (int i=0; i<(int)tracks.size(); i++) {
int index = tracks.at(i) - 1;
if ((index < 0) || (index > (int)m_kernSpines.size() - 1)) {
continue;
}
m_selectedKernSpines.push_back(m_kernSpines.at(index));
}
} else if (!m_spineTracks.empty()) {
int maxTrack = infile.getMaxTrack();
vector<int> tracks = Convert::extractIntegerList(m_spineTracks, maxTrack);
sort(tracks.begin(),tracks.end());
tracks.erase(unique(tracks.begin(), tracks.end()), tracks.end());
for (int i=0; i<(int)tracks.size(); i++) {
int track = tracks.at(i);
if ((track < 1) || (track > maxTrack)) {
continue;
}
for (int j=0; j<(int)m_kernSpines.size(); j++) {
int ktrack = m_kernSpines.at(j)->getTrack();
if (ktrack == track) {
m_selectedKernSpines.push_back(m_kernSpines.at(j));
}
}
}
} else {
// analyzing all **kern tracks
m_selectedKernSpines = m_kernSpines;
}

std::vector<int> spineIndices(m_selectedKernSpines.size());
std::transform(m_selectedKernSpines.begin(), m_selectedKernSpines.end(), spineIndices.begin(),
[](const HTp token) {
return token->getSpineIndex();
});

return spineIndices;
}





/////////////////////////////////
//
Expand Down
Loading