Skip to content

Commit

Permalink
Merge pull request #53 from WolfgangDrescher/figuredbass
Browse files Browse the repository at this point in the history
Add automatically created `**fb` spine
  • Loading branch information
craigsapp authored Jan 21, 2023
2 parents eb7c560 + fa906a0 commit ec63ae7
Show file tree
Hide file tree
Showing 7 changed files with 1,621 additions and 487 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ set(SRCS
src/tool-dissonant.cpp
src/tool-esac2hum.cpp
src/tool-extract.cpp
src/tool-fb.cpp
src/tool-filter.cpp
src/tool-hproof.cpp
src/tool-imitation.cpp
Expand Down Expand Up @@ -148,6 +149,7 @@ set(HDRS
include/tool-dissonant.h
include/tool-esac2hum.h
include/tool-extract.h
include/tool-fb.h
include/tool-hproof.h
include/tool-imitation.h
include/tool-mei2hum.h
Expand Down
12 changes: 11 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,16 @@ tool-extract.o: tool-extract.cpp tool-extract.h \
HumHash.h HumParamSet.h HumdrumFileStream.h \
HumRegex.h

tool-fb.o: tool-fb.cpp tool-fb.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-filter.o: tool-filter.cpp tool-filter.h \
HumTool.h Options.h HumdrumFileSet.h \
HumdrumFile.h HumdrumFileContent.h \
Expand All @@ -632,7 +642,7 @@ tool-filter.o: tool-filter.cpp tool-filter.h \
tool-chooser.h tool-chord.h tool-cint.h \
NoteGrid.h NoteCell.h HumRegex.h \
tool-composite.h tool-dissonant.h \
tool-extract.h tool-homorhythm.h \
tool-extract.h tool-fb.h tool-homorhythm.h \
tool-homorhythm2.h tool-hproof.h \
tool-humdiff.h tool-shed.h tool-imitation.h \
tool-kern2mens.h tool-melisma.h tool-metlev.h \
Expand Down
101 changes: 76 additions & 25 deletions include/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 Jan 19 21:53:43 PST 2023
// Last Modified: Sa 21 Jan 2023 09:48:51 CET
// Filename: humlib.h
// URL: https://github.com/craigsapp/humlib/blob/master/include/humlib.h
// Syntax: C++11
Expand Down Expand Up @@ -7231,37 +7231,88 @@ class Tool_extract : public HumTool {



class FiguredBassNumber {
public:
FiguredBassNumber(int num, string accid, bool showAccid, int voiceIndex, int lineIndex, bool isAttack, bool intervallsatz);
std::string toString(bool nonCompoundIntervalsQ, bool noAccidentalsQ, bool hideThreeQ);
int getNumberWithinOctave(void);

int m_voiceIndex;
int m_lineIndex;
int m_number;
std::string m_accidentals;
bool m_showAccidentals; // Force shoing figured base numbers when they need an accidental
bool m_baseOfSustainedNoteDidChange;
bool m_isAttack;
bool m_convert2To9 = false;
bool m_intervallsatz = false;

};

class FiguredBassAbbreviationMapping {
public:
FiguredBassAbbreviationMapping(string s, vector<int> n);

static vector<FiguredBassAbbreviationMapping*> s_mappings;

// String to compare the numbers with
// e.g. "6 4 3"
// Sorted by size, larger numbers first
string m_str;

// Figured bass number as int
vector<int> m_numbers;

};

class Tool_fb : public HumTool {

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

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

protected:
void processFile (HumdrumFile& infile);
void initialize (void);
void processLine (HumdrumFile& infile, int index);
void setupScoreData (HumdrumFile& infile);
void getAnalyses (HumdrumFile& infile);
void getHarmonicIntervals(HumdrumFile& infile);
void calculateIntervals(vector<int>& intervals, vector<HTp>& tokens, int bassIndex);
void printOutput (HumdrumFile& infile);
void printLineStyle3 (HumdrumFile& infile, int line);
std::string getAnalysisTokenStyle3(HumdrumFile& infile, int line, int field);
void initialize (void);
void processFile (HumdrumFile& infile);
bool hideNumbersForTokenLine (HTp token, pair<int, HumNum> timeSig);
vector<string> getTrackData (const vector<FiguredBassNumber*>& numbers, int lineCount);
vector<string> getTrackDataForVoice (int voiceIndex, const vector<FiguredBassNumber*>& numbers, int lineCount);
FiguredBassNumber* createFiguredBassNumber (int basePitchBase40, int targetPitchBase40, int voiceIndex, int lineIndex, bool isAttack, string keySignature);
vector<FiguredBassNumber*> filterNegativeNumbers (vector<FiguredBassNumber*> numbers);
vector<FiguredBassNumber*> filterFiguredBassNumbersForLine (vector<FiguredBassNumber*> numbers, int lineIndex);
vector<FiguredBassNumber*> filterFiguredBassNumbersForLineAndVoice(vector<FiguredBassNumber*> numbers, int lineIndex, int voiceIndex);
string formatFiguredBassNumbers (const vector<FiguredBassNumber*>& numbers);
vector<FiguredBassNumber*> analyzeChordNumbers (const vector<FiguredBassNumber*>& numbers);
vector<FiguredBassNumber*> getAbbreviatedNumbers (const vector<FiguredBassNumber*>& numbers);
string getNumberString (vector<FiguredBassNumber*> numbers);
string getKeySignature (HumdrumFile& infile, int lineIndex);
int getLowestBase40Pitch (vector<int> base40Pitches);


private:
std::vector<HTp> m_kernspines;
std::vector<int> m_kerntracks;
std::vector<int> m_track2index;
std::vector<std::vector<int>> m_keyaccid;
std::vector<std::vector<int>> m_intervals;
const int m_rest = -1000;
int m_reference = 0; // currently fixed to bass
int m_debugQ = false;
bool m_compoundQ = false;
bool m_accidentalsQ = false;
int m_baseTrackQ = 1;
bool m_intervallsatzQ = false;
bool m_sortQ = false;
bool m_lowestQ = false;
bool m_normalizeQ = false;
bool m_abbrQ = false;
bool m_attackQ = false;
bool m_figuredbassQ = false;
bool m_hideThreeQ = false;
bool m_showNegativeQ = false;
bool m_aboveQ = false;
string m_recipQ = "";

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

};

Expand Down
113 changes: 80 additions & 33 deletions include/tool-fb.h
Original file line number Diff line number Diff line change
@@ -1,57 +1,107 @@
//
// Programmer: Craig Stuart Sapp <[email protected]>
// Creation Date: Wed Mar 9 21:50:25 PST 2022
// Last Modified: Wed Mar 9 21:50:28 PST 2022
// Programmer: Wolfgang Drescher <[email protected]>
// Creation Date: Sun Nov 27 2022 00:25:34 CET
// Filename: tool-fb.h
// URL: https://github.com/craigsapp/humlib/blob/master/include/tool-fb.h
// Syntax: C++11; humlib
// vim: ts=3 noexpandtab
// vim: syntax=cpp ts=3 noexpandtab nowrap
//
// Description: Extract figured bass numbers from musical content.
// Reference: https://github.com/WolfgangDrescher/humdrum-figured-bass-filter-demo
// Description: Interface for fb tool, which automatically adds figured bass numbers.
//

#ifndef _TOOL_FB_H
#define _TOOL_FB_H

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

namespace hum {

// START_MERGE

class FiguredBassNumber {
public:
FiguredBassNumber(int num, string accid, bool showAccid, int voiceIndex, int lineIndex, bool isAttack, bool intervallsatz);
std::string toString(bool nonCompoundIntervalsQ, bool noAccidentalsQ, bool hideThreeQ);
int getNumberWithinOctave(void);

int m_voiceIndex;
int m_lineIndex;
int m_number;
std::string m_accidentals;
bool m_showAccidentals; // Force shoing figured base numbers when they need an accidental
bool m_baseOfSustainedNoteDidChange;
bool m_isAttack;
bool m_convert2To9 = false;
bool m_intervallsatz = false;

};

class FiguredBassAbbreviationMapping {
public:
FiguredBassAbbreviationMapping(string s, vector<int> n);

static vector<FiguredBassAbbreviationMapping*> s_mappings;

// String to compare the numbers with
// e.g. "6 4 3"
// Sorted by size, larger numbers first
string m_str;

// Figured bass number as int
vector<int> m_numbers;

};

class Tool_fb : public HumTool {

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

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

protected:
void processFile (HumdrumFile& infile);
void initialize (void);
void processLine (HumdrumFile& infile, int index);
void setupScoreData (HumdrumFile& infile);
void getAnalyses (HumdrumFile& infile);
void getHarmonicIntervals(HumdrumFile& infile);
void calculateIntervals(vector<int>& intervals, vector<HTp>& tokens, int bassIndex);
void printOutput (HumdrumFile& infile);
void printLineStyle3 (HumdrumFile& infile, int line);
std::string getAnalysisTokenStyle3(HumdrumFile& infile, int line, int field);
void initialize (void);
void processFile (HumdrumFile& infile);
bool hideNumbersForTokenLine (HTp token, pair<int, HumNum> timeSig);
vector<string> getTrackData (const vector<FiguredBassNumber*>& numbers, int lineCount);
vector<string> getTrackDataForVoice (int voiceIndex, const vector<FiguredBassNumber*>& numbers, int lineCount);
FiguredBassNumber* createFiguredBassNumber (int basePitchBase40, int targetPitchBase40, int voiceIndex, int lineIndex, bool isAttack, string keySignature);
vector<FiguredBassNumber*> filterNegativeNumbers (vector<FiguredBassNumber*> numbers);
vector<FiguredBassNumber*> filterFiguredBassNumbersForLine (vector<FiguredBassNumber*> numbers, int lineIndex);
vector<FiguredBassNumber*> filterFiguredBassNumbersForLineAndVoice(vector<FiguredBassNumber*> numbers, int lineIndex, int voiceIndex);
string formatFiguredBassNumbers (const vector<FiguredBassNumber*>& numbers);
vector<FiguredBassNumber*> analyzeChordNumbers (const vector<FiguredBassNumber*>& numbers);
vector<FiguredBassNumber*> getAbbreviatedNumbers (const vector<FiguredBassNumber*>& numbers);
string getNumberString (vector<FiguredBassNumber*> numbers);
string getKeySignature (HumdrumFile& infile, int lineIndex);
int getLowestBase40Pitch (vector<int> base40Pitches);


private:
std::vector<HTp> m_kernspines;
std::vector<int> m_kerntracks;
std::vector<int> m_track2index;
std::vector<std::vector<int>> m_keyaccid;
std::vector<std::vector<int>> m_intervals;
const int m_rest = -1000;
int m_reference = 0; // currently fixed to bass
int m_debugQ = false;
bool m_compoundQ = false;
bool m_accidentalsQ = false;
int m_baseTrackQ = 1;
bool m_intervallsatzQ = false;
bool m_sortQ = false;
bool m_lowestQ = false;
bool m_normalizeQ = false;
bool m_abbrQ = false;
bool m_attackQ = false;
bool m_figuredbassQ = false;
bool m_hideThreeQ = false;
bool m_showNegativeQ = false;
bool m_aboveQ = false;
string m_recipQ = "";

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

};

Expand All @@ -60,6 +110,3 @@ class Tool_fb : public HumTool {
} // end namespace hum

#endif /* _TOOL_FB_H */



Loading

0 comments on commit ec63ae7

Please sign in to comment.