Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add automatically created **fb spine #53

Merged
merged 113 commits into from
Jan 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
113 commits
Select commit Hold shift + click to select a range
889e18e
Add basic implementation for figuredbass filter
WolfgangDrescher Nov 26, 2022
91946d2
Fix typo
WolfgangDrescher Nov 27, 2022
e1a6c3a
Remove unused var
WolfgangDrescher Nov 27, 2022
a33cd71
Refactor with classes
WolfgangDrescher Nov 27, 2022
ec80ffe
Remove FiguredBassTrack and FiguredBassSlice
WolfgangDrescher Nov 27, 2022
fd096f1
Add intervallsatz feature
WolfgangDrescher Nov 27, 2022
6a4f4b4
Add feature to sort figured bass numbers by interval
WolfgangDrescher Nov 27, 2022
7ec9c5d
Fix compound octave
WolfgangDrescher Nov 28, 2022
25b50a9
Add feature for lowest note as base
WolfgangDrescher Nov 28, 2022
f7ee3fc
Remove cout
WolfgangDrescher Nov 28, 2022
5896b8e
Refactor var names
WolfgangDrescher Nov 28, 2022
7940156
Rename nonCompoundIntervalsQ to compoundQ
WolfgangDrescher Nov 28, 2022
7d8579f
Rename noAccidentalsQ to accidentalsQ
WolfgangDrescher Nov 28, 2022
8769e03
Improve accidentals support
WolfgangDrescher Nov 28, 2022
16c03a2
Remove accidentals that are already present in the key signature
WolfgangDrescher Nov 28, 2022
d73e246
Add feature to normalize figured bass numbers
WolfgangDrescher Nov 28, 2022
deff304
Add feature for abbreviated figures
WolfgangDrescher Nov 29, 2022
f1f049e
Remove unused if section
WolfgangDrescher Nov 29, 2022
6565197
Remove option flags as parameters
WolfgangDrescher Nov 29, 2022
31703c4
Fix missing accidentals for abbreviated figures
WolfgangDrescher Nov 29, 2022
7b36474
Fix missing accidentals for octaves and unisons
WolfgangDrescher Nov 29, 2022
eef094d
Fix missing 7
WolfgangDrescher Nov 29, 2022
bd9c99f
Improve text
WolfgangDrescher Nov 29, 2022
0591008
Add feature to hide intervals when they are sustained and the base is…
WolfgangDrescher Nov 29, 2022
8114128
Fix indentation
WolfgangDrescher Dec 22, 2022
b96d656
Align variable values
WolfgangDrescher Dec 22, 2022
fbaeee0
Rename figuredbass command to fb
WolfgangDrescher Dec 22, 2022
26e815e
Merge branch 'master' into figuredbass
WolfgangDrescher Jan 11, 2023
4cce120
Rename var normalizededNumbers with formattedNumbers
WolfgangDrescher Jan 11, 2023
7897d59
Fix lastNumbers and currentNumbers size
WolfgangDrescher Jan 11, 2023
a4e32ce
Remove unused trackIndex
WolfgangDrescher Jan 11, 2023
15a13d8
Add comments
WolfgangDrescher Jan 11, 2023
6db9780
Add missing numbers variable
WolfgangDrescher Jan 11, 2023
a907db4
Fix indentation
WolfgangDrescher Jan 11, 2023
d307809
Use constant pass-by-reference for vectors
WolfgangDrescher Jan 11, 2023
e972e2e
Add space after reserved words (if)
WolfgangDrescher Jan 11, 2023
9681430
Add parentheses around statements in conditions
WolfgangDrescher Jan 11, 2023
0647271
Add void to method declaration and definition
WolfgangDrescher Jan 11, 2023
74568d8
Remove semicolon from end of function definitions
WolfgangDrescher Jan 11, 2023
ce9855d
Rename getNumberB7 to getNumberWithinOctave
WolfgangDrescher Jan 11, 2023
df239cc
Rename getAbbrNumbers to getAbbreviatedNumbers
WolfgangDrescher Jan 11, 2023
558debf
Improve names
WolfgangDrescher Jan 11, 2023
7f389bb
Use static variable for mappings
WolfgangDrescher Jan 11, 2023
a99b7bc
Prefix member variables and format FiguredBassNumber declaration
WolfgangDrescher Jan 11, 2023
da7f9a7
Format Tool_fb declaration
WolfgangDrescher Jan 11, 2023
ee8b5b9
Add m_ prefix to Tool_fb class properties
WolfgangDrescher Jan 11, 2023
dfd991c
Format FiguredBassAbbreviationMapping declaration
WolfgangDrescher Jan 11, 2023
3d129ee
Add m_ prefix to FiguredBassAbbreviationMapping
WolfgangDrescher Jan 11, 2023
d56fe04
Fix ordering of accid and number
WolfgangDrescher Jan 11, 2023
7eeb1c8
Add figuredbass (-f) cli option as shortcut for -c -a -s -l -n -r
WolfgangDrescher Jan 11, 2023
c5d9558
Add hide-three cli option
WolfgangDrescher Jan 11, 2023
cb28bb3
Import cmath for abs function
WolfgangDrescher Jan 11, 2023
32bfef5
Use lowercase
WolfgangDrescher Jan 11, 2023
c7eed01
Fix accidentals display
WolfgangDrescher Jan 12, 2023
1ef9bd4
Add new line
WolfgangDrescher Jan 12, 2023
00c51a9
Remove lines
WolfgangDrescher Jan 12, 2023
94c30bc
Add support for negative numbers
WolfgangDrescher Jan 12, 2023
bfb1be9
Add cli option --fba to display numbers above the staff
WolfgangDrescher Jan 12, 2023
efd737a
Fix num for rests
WolfgangDrescher Jan 12, 2023
58f1049
Replace single quotes with double quotes
WolfgangDrescher Jan 12, 2023
b6fa671
Fix num calculation for rests and unisono
WolfgangDrescher Jan 12, 2023
2945208
Fix accidentals for sustained notes
WolfgangDrescher Jan 12, 2023
3d88ec5
Simplify getNumberWithinOctave
WolfgangDrescher Jan 12, 2023
8406ffa
Replace 2 with 9 if a 3 is included in the chord numbers
WolfgangDrescher Jan 12, 2023
f942d63
Remove -l from --figuredbass
WolfgangDrescher Jan 12, 2023
b59747f
Improve description for --normalize and --abbr
WolfgangDrescher Jan 12, 2023
9eadefb
Fix shown 7 at rests again
WolfgangDrescher Jan 12, 2023
bdee55e
Add support for display numbers on certain rhythmic positions
WolfgangDrescher Jan 13, 2023
9e6ae2c
Rename option --fba to --above
WolfgangDrescher Jan 13, 2023
2c35952
Change signifier for negative numbers to v
WolfgangDrescher Jan 13, 2023
bd337eb
Change signifier for negative figured bass numbers to `~`
WolfgangDrescher Jan 13, 2023
7aad91a
Fix typo
WolfgangDrescher Jan 13, 2023
728fd0b
Allow unisono in intervallsatz if --compound
WolfgangDrescher Jan 13, 2023
cc65cd2
Ignore number if either base or target is a rest or silent note
WolfgangDrescher Jan 13, 2023
bcfc1d9
Add initialize and processFile methods
WolfgangDrescher Jan 14, 2023
7f849bd
Make createFiguredBassNumber independent of NoteGrid
WolfgangDrescher Jan 14, 2023
2ac8da8
Fix display for 7 when --compound flag is set
WolfgangDrescher Jan 14, 2023
54d82e0
Add support for chords
WolfgangDrescher Jan 14, 2023
0cde52b
Include chord notes of base voice
WolfgangDrescher Jan 14, 2023
5c6dfb9
Sort numbers for unordered chord pitches
WolfgangDrescher Jan 14, 2023
c410410
Improve readability
WolfgangDrescher Jan 15, 2023
df8be20
Handle spine splits
WolfgangDrescher Jan 15, 2023
4ae1d0e
Improvements for chords in base voice
WolfgangDrescher Jan 15, 2023
6d441f9
Improve --lowest for chords
WolfgangDrescher Jan 15, 2023
c061511
Add todos
WolfgangDrescher Jan 15, 2023
e95ba8f
Ignore voices if track is not active by --kern-tracks or --spine-tracks
WolfgangDrescher Jan 15, 2023
c069fc7
Rename -s to -o
WolfgangDrescher Jan 15, 2023
a2a9813
Commit humlib.h and humlib.cpp
WolfgangDrescher Jan 15, 2023
eda350b
Merge branch 'master' into figuredbass
WolfgangDrescher Jan 15, 2023
ce550c2
Use kern track numbering for --base instead of voice index
WolfgangDrescher Jan 15, 2023
6b3f97d
Add brackets
WolfgangDrescher Jan 16, 2023
fd3923a
Handle wrong base track input
WolfgangDrescher Jan 16, 2023
1a35705
Build humlib
WolfgangDrescher Jan 16, 2023
6c3a576
Add --frequency as alternative to --recip
WolfgangDrescher Jan 16, 2023
404b433
Fix getString to frequency
WolfgangDrescher Jan 16, 2023
6273e0f
Fix --lowest option
WolfgangDrescher Jan 16, 2023
bda171c
Improve variable name for usedBaseKernTrack
WolfgangDrescher Jan 16, 2023
75e09b4
Improvements for sustained notes
WolfgangDrescher Jan 16, 2023
834cc93
Fix -t for chords
WolfgangDrescher Jan 16, 2023
357c786
Rename -t option to ties
WolfgangDrescher Jan 16, 2023
5ce0978
Update humlib.h and humlib.cpp
WolfgangDrescher Jan 16, 2023
46a1c93
Fix missing 1 in unisono
WolfgangDrescher Jan 16, 2023
bd09768
Ignore grace notes
WolfgangDrescher Jan 16, 2023
d7f1db7
Handle spine splits to get lowest pitch for base track
WolfgangDrescher Jan 17, 2023
02fee56
Merge branch 'master' into figuredbass
WolfgangDrescher Jan 17, 2023
e71c45b
Remove cerr
WolfgangDrescher Jan 17, 2023
8fa386b
Add braces
WolfgangDrescher Jan 17, 2023
f79f52c
Fix spine split when there is a rest in primary token
WolfgangDrescher Jan 17, 2023
bc7d0d7
Handle spine splits with --lowest flag
WolfgangDrescher Jan 17, 2023
5b44429
Update humlib.h and humlib.cpp
WolfgangDrescher Jan 17, 2023
eff5056
Rename m_processTrack with m_selectedKernSpines
WolfgangDrescher Jan 21, 2023
8e1c055
Add infile content to m_humdrum_text
WolfgangDrescher Jan 21, 2023
fa906a0
Merge branch 'master' into figuredbass
WolfgangDrescher Jan 21, 2023
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 @@ -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