Skip to content

Commit

Permalink
Merge pull request #3767 from rism-digital/develop-humdrum
Browse files Browse the repository at this point in the history
Add esac import and capture cerr to Log*() system
  • Loading branch information
lpugin authored Sep 10, 2024
2 parents f94ee22 + bf6b697 commit cd74bcd
Show file tree
Hide file tree
Showing 6 changed files with 36,479 additions and 30,907 deletions.
320 changes: 303 additions & 17 deletions include/hum/humlib.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//
// Programmer: Craig Stuart Sapp <[email protected]>
// Creation Date: Sat Aug 8 12:24:49 PDT 2015
// Last Modified: Thu Aug 8 21:55:11 PDT 2024
// Last Modified: Sun Sep 8 23:07:16 PDT 2024
// Filename: min/humlib.h
// URL: https://github.com/craigsapp/humlib/blob/master/min/humlib.h
// Syntax: C++11
Expand Down Expand Up @@ -964,9 +964,9 @@ class HumInstrument {
int setGM (const std::string& Hname, int aValue);

private:
int index;
static std::vector<_HumInstrument> data;
static int classcount;
int m_index;
static std::vector<_HumInstrument> m_data;
static int m_classcount;

protected:
void initialize (void);
Expand Down Expand Up @@ -2043,6 +2043,7 @@ class HumdrumFileBase : public HumHash {
bool isRhythmAnalyzed (void);
bool areStrandsAnalyzed (void);
bool areStrophesAnalyzed (void);
void setFilenameFromSegment (void);

template <class TYPE>
void initializeArray (std::vector<std::vector<TYPE>>& array, TYPE value);
Expand Down Expand Up @@ -7358,6 +7359,201 @@ class Tool_double : public HumTool {
};


class Tool_esac2hum : public HumTool {
public:

class Note {
public:
std::vector<std::string> m_errors;
std::string esac;
int m_dots = 0;
int m_underscores = 0;
int m_octave = 0;
int m_degree = 0; // scale degree (wrt major key)
int m_b40degree = 0; // scale degree as b40 interval
int m_alter = 0; // chromatic alteration of degree (flats/sharp from major scale degrees)
double m_ticks = 0.0;
bool m_tieBegin = false;
bool m_tieEnd = false;
bool m_phraseBegin = false;
bool m_phraseEnd = false;
std::string m_humdrum; // **kern conversion of EsAC note
int m_b40 = 0; // absolute b40 pitch (-1000 = rest);
int m_b12 = 0; // MIDI note number (-1000 = rest);
HumNum m_factor = 1; // for triplet which is 2/3 duration

void calculateRhythms(int minrhy);
void calculatePitches(int tonic);
bool parseNote(const std::string& note, HumNum factor);
void generateHumdrum(int minrhy, int b40tonic);
bool isPitch(void);
bool isRest(void);
std::string getScaleDegree(void);
};

class Measure : public std::vector<Tool_esac2hum::Note> {
public:
std::vector<std::string> m_errors;
std::string esac;
int m_barnum = -1000; // -1000 == unassigned bar number for this measure
// m_barnum = -1 == invisible barline (between two partial measures)
// m_barnum = 0 == pickup measure (partial measure at start of music)
double m_ticks = 0.0;
double m_tsticks = 0.0;
// m_measureTimeSignature is a **kern time signature
// (change) to display in the converted score.
std::string m_measureTimeSignature = "";
bool m_partialBegin = false; // start of an incomplete measure
bool m_partialEnd = false; // end of an incomplete measure (pickup)
bool m_complete = false; // a complste measure
void calculateRhythms(int minrhy);
void calculatePitches(int tonic);
bool parseMeasure(const std::string& measure);
bool isUnassigned(void);
void setComplete(void);
bool isComplete(void);
void setPartialBegin(void);
bool isPartialBegin(void);
void setPartialEnd(void);
bool isPartialEnd(void);
};

class Phrase : public std::vector<Tool_esac2hum::Measure> {
public:
std::vector<std::string> m_errors;
double m_ticks = 0.0;
std::string esac;
void calculateRhythms(int minrhy);
void calculatePitches(int tonic);
bool parsePhrase(const std::string& phrase);
std::string getLastScaleDegree();
void getNoteList(std::vector<Tool_esac2hum::Note*>& notelist);
std::string getNO_REP(void);
int getFullMeasureCount(void);
};

class Score : public std::vector<Tool_esac2hum::Phrase> {
public:
int m_b40tonic = 0;
int m_minrhy = 0;
std::string m_clef;
std::string m_keysignature;
std::string m_keydesignation;
std::string m_timesig;
std::map<std::string, std::string> m_params;
std::vector<std::string> m_errors;
bool m_finalBarline = false;
bool hasFinalBarline(void) { return m_finalBarline; }
void calculateRhythms(int minrhy);
void calculatePitches(int tonic);
bool parseMel(const std::string& mel);
void analyzeTies(void);
void analyzePhrases(void);
void getNoteList(std::vector<Tool_esac2hum::Note*>& notelist);
void getMeasureList(std::vector<Tool_esac2hum::Measure*>& measurelist);
void getPhraseNoteList(std::vector<Tool_esac2hum::Note*>& notelist, int index);
void generateHumdrumNotes(void);
void calculateClef(void);
void calculateKeyInformation(void);
void calculateTimeSignatures(void);
void setAllTimesigTicks(double ticks);
void assignFreeMeasureNumbers(void);
void assignSingleMeasureNumbers(void);
void prepareMultipleTimeSignatures(const std::string& ts);

void doAnalyses(void);
void analyzeMEL_SEM(void);
void analyzeMEL_RAW(void);
void analyzeNO_REP(void);
void analyzeRTM(void);
void analyzeSCL_DEG(void);
void analyzeSCL_SEM(void);
void analyzePHR_NO(void);
void analyzePHR_BARS(void);
void analyzePHR_CAD(void);
void analyzeACC(void);
};

Tool_esac2hum (void);
~Tool_esac2hum () {};

bool convertFile (std::ostream& out, const std::string& filename);
bool convert (std::ostream& out, const std::string& input);
bool convert (std::ostream& out, std::istream& input);


protected:
void initialize (void);

void convertEsacToHumdrum(std::ostream& output, std::istream& infile);
bool getSong (std::vector<std::string>& song, std::istream& infile);
void convertSong (std::ostream& output, std::vector<std::string>& infile);
static std::string trimSpaces (const std::string& input);
void printHeader (std::ostream& output);
void printFooter (std::ostream& output, std::vector<std::string>& infile);
void printConversionDate (std::ostream& output);
void printPdfLinks (std::ostream& output);
void printParameters (void);
void printPageNumbers (std::ostream& output);
void getParameters (std::vector<std::string>& infile);
void cleanText (std::string& buffer);
std::string createFilename (void);
void printBemComment (std::ostream& output);
void processSong (void);
void printScoreContents (std::ostream& output);
void embedAnalyses (std::ostream& output);
void printPdfUrl (std::ostream& output);
std::string getKolbergUrl (int volume);
void printKolbergPdfUrl (std::ostream& output);

private:
bool m_debugQ = false; // used with --debug option
bool m_verboseQ = false; // used with --verbose option
std::string m_verbose; // p = print EsAC phrases, m = print measures, n = print notes.
// t after p, m, or n means print tick info
bool m_embedEsacQ = true; // used with -E option
bool m_dwokQ = false; // true if source is Oskar Kolberg: Dzieła Wszystkie
// (Oskar Kolberg: Complete Works)
// determined automatically if header line or TRD source contains "DWOK" string.
bool m_analysisQ = false; // used with -a option

int m_inputline = 0; // used to keep track if the EsAC input line.

std::string m_filePrefix;
std::string m_filePostfix = ".krn";
bool m_fileTitleQ = false;

std::string m_prevline;
std::string m_cutline;
std::vector<std::string> m_globalComments;

bool m_initialized = false;
int m_minrhy = 0;

Tool_esac2hum::Score m_score;

class KolbergInfo {
public:
std::string titlePL;
std::string titleEN;
int firstPrintPage;
int firstScanPage;
std::vector<int> plates;

KolbergInfo(void) { firstPrintPage = 0; firstScanPage = 0; }
KolbergInfo(
const std::string& pl, const std::string& en, int fpp, int fsp, const std::vector<int>& plts)
: titlePL(pl), titleEN(en), firstPrintPage(fpp), firstScanPage(fsp), plates(plts) {}
};
std::map<int, KolbergInfo> m_kinfo;
KolbergInfo getKolbergInfo(int volume);
std::string getKolbergUrl(int volume, int printPage);
int calculateScanPage(int inputPrintPage, int printPage, int scanPage, const std::vector<int>& platePages);


};



#define ND_NOTE 0 /* notes or rests + text and phrase markings */
#define ND_BAR 1 /* explicit barlines */
Expand Down Expand Up @@ -7387,10 +7583,10 @@ class NoteData {



class Tool_esac2hum : public HumTool {
class Tool_esac2humold : public HumTool {
public:
Tool_esac2hum (void);
~Tool_esac2hum () {};
Tool_esac2humold (void);
~Tool_esac2humold () {};

bool convertFile (std::ostream& out, const std::string& filename);
bool convert (std::ostream& out, const std::string& input);
Expand Down Expand Up @@ -7438,16 +7634,18 @@ class Tool_esac2hum : public HumTool {
void printHumdrumFooterInfo(std::ostream& out, std::vector<std::string>& song);

private:
int debugQ = 0; // used with --debug option
int verboseQ = 0; // used with -v option
int splitQ = 0; // used with -s option
int firstfilenum = 1; // used with -f option
std::vector<std::string> header; // used with -h option
std::vector<std::string> trailer; // used with -t option
std::string fileextension; // used with -x option
std::string namebase; // used with -s option

std::vector<int> chartable; // used printChars() & printSpecialChars()
int debugQ = 0; // used with --debug option
int verboseQ = 0; // used with -v option
int splitQ = 0; // used with -s option
int firstfilenum = 1; // used with -f option
std::vector<std::string> header; // used with -h option
std::vector<std::string> trailer; // used with -t option
std::string fileextension; // used with -x option
std::string namebase; // used with -s option

// Modern ESaC files use UTF-8 characters, older ESaC files use
// ASCII encodings of non-UTF7 characters:
std::vector<int> chartable; // used in printChars() & printSpecialChars()
int inputline = 0;

};
Expand Down Expand Up @@ -10939,6 +11137,94 @@ class Tool_tabber : public HumTool {



class Tool_tandeminfo : public HumTool {
public:
class Entry {
public:
HTp token = NULL;
std::string description;
int count = 0;
};

Tool_tandeminfo (void);
~Tool_tandeminfo () {};

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


protected:
void initialize (void);
void processFile (HumdrumFile& infile);
void printEntries (HumdrumFile& infile);
void printEntriesHtml (HumdrumFile& infile);
void printEntriesText (HumdrumFile& infile);
void doCountAnalysis (void);

std::string getDescription (HTp token);
std::string checkForKeySignature (const std::string& tok);
std::string checkForKeyDesignation (const std::string& tok);
std::string checkForInstrumentInfo (const std::string& tok);
std::string checkForLabelInfo (const std::string& tok);
std::string checkForTimeSignature (const std::string& tok);
std::string checkForMeter (const std::string& tok);
std::string checkForTempoMarking (const std::string& tok);
std::string checkForClef (const std::string& tok);
std::string checkForStaffPartGroup (const std::string& tok);
std::string checkForTuplet (const std::string& tok);
std::string checkForHands (const std::string& tok);
std::string checkForPosition (const std::string& tok);
std::string checkForCue (const std::string& tok);
std::string checkForFlip (const std::string& tok);
std::string checkForTremolo (const std::string& tok);
std::string checkForOttava (const std::string& tok);
std::string checkForPedal (const std::string& tok);
std::string checkForBracket (const std::string& tok);
std::string checkForRscale (const std::string& tok);
std::string checkForTimebase (const std::string& tok);
std::string checkForTransposition (const std::string& tok);
std::string checkForGrp (const std::string& tok);
std::string checkForStria (const std::string& tok);
std::string checkForFont (const std::string& tok);
std::string checkForVerseLabels (const std::string& tok);
std::string checkForLanguage (const std::string& tok);
std::string checkForStemInfo (const std::string& tok);
std::string checkForXywh (const std::string& tok);
std::string checkForCustos (const std::string& tok);
std::string checkForTextInterps (const std::string& tok);
std::string checkForRep (const std::string& tok);
std::string checkForPline (const std::string& tok);
std::string checkForTacet (const std::string& tok);
std::string checkForFb (const std::string& tok);
std::string checkForColor (const std::string& tok);
std::string checkForThru (const std::string& tok);

private:
bool m_exclusiveQ = true; // used with -X option (don't print exclusive interpretation)
bool m_unknownQ = false; // used with -u option (print only unknown tandem interpretations)
bool m_filenameQ = false; // used with -f option (print only unknown tandem interpretations)
bool m_descriptionQ = false; // used with -m option (print description of interpretation)
bool m_locationQ = false; // used with -l option (print location of interpretation in file)
bool m_zeroQ = false; // used with -z option (location address by 0-index)
bool m_tableQ = false; // used with -t option (display results as HTML table)
bool m_closeQ = false; // used with --close option (HTML details closed by default)
bool m_sortQ = false; // used with -s (sort entries alphabetically by tandem interpretation)
bool m_headerOnlyQ = false; // used with -h option (process only header interpretations)
bool m_bodyOnlyQ = false; // used with -H option (process only body interpretations)
bool m_countQ = false; // used with -c option (only show unique list with counts);
bool m_sortByCountQ = false; // used with -c and -n options (sort from low to high count)
bool m_sortByReverseCountQ = false; // used with -c and -N options (sort from high to low count)
bool m_humdrumQ = false; // used with --humdrum option (output data formatted with Humdrum syntax)

std::string m_unknown = "unknown";

std::vector<Tool_tandeminfo::Entry> m_entries;
std::map<std::string, int> m_count;
};


class Tool_tassoize : public HumTool {
public:
Tool_tassoize (void);
Expand Down
Loading

0 comments on commit cd74bcd

Please sign in to comment.