Skip to content

Commit

Permalink
Code cleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
Leethine committed Nov 29, 2021
1 parent 064d689 commit 751138f
Show file tree
Hide file tree
Showing 8 changed files with 154 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/notation/defs/tonality.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ enum class TonalityType {

using TonalityNameTypeTable=std::map<NoteName, TonalityType>;

TonalityNameTypeTable tonality_str_type_table {
TonalityNameTypeTable TONALITY_STR_TYPE_TABLE {
// Majors
{ "C", TonalityType::C },
{ "G", TonalityType::G },
Expand Down Expand Up @@ -83,7 +83,7 @@ TonalityNameTypeTable tonality_str_type_table {
{ "Dm", TonalityType::d }
};

std::map<TonalityType, TonalityType> circle_of_fifth {
std::map<TonalityType, TonalityType> CIRCLE_OF_FIFTH {
// Major to minor
{TonalityType::C, TonalityType::a},
{TonalityType::G, TonalityType::e},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct NoteOrnament {
boost::to_lower(lkey);
boost::to_lower(lval);

std::set<std::string> valid_keys {
const std::set<std::string> valid_keys {
"acciaccatura", "appoggiatura", "arpeggio",
"cadenza", "dinamica", "fioritura", "glissando",
"gruppetto", "mordente", "tremolo", "trillo"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ struct HarpsichordNoteProperty : NoteProperty {
boost::to_lower(lkey);
boost::to_lower(lval);

std::set<std::string> valid_keys {
const std::set<std::string> valid_keys {
"waits","lasts","delay"
};
auto search = valid_keys.find(lkey);
Expand All @@ -31,7 +31,7 @@ struct LuthNoteProperty : NoteProperty {
boost::to_lower(lkey);
boost::to_lower(lval);

std::set<std::string> valid_keys {
const std::set<std::string> valid_keys {
"waits","lasts","delay","force","stringnbr"
};
auto search = valid_keys.find(lkey);
Expand All @@ -51,7 +51,7 @@ struct SineWaveNoteProperty : NoteProperty {
boost::to_lower(lkey);
boost::to_lower(lval);

std::set<std::string> valid_keys {
const std::set<std::string> valid_keys {
"waits","lasts"
};
auto search = valid_keys.find(lkey);
Expand Down
2 changes: 1 addition & 1 deletion src/notation/measure/notation_sys.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ enum class NotationSystemType {
HELMHOLTZ
};

const std::map<NotationSystemName,NotationSystemType> notation_system_table {
const std::map<NotationSystemName,NotationSystemType> NOTATION_SYSTEM_TABLE {
{"Latin", NotationSystemType::LATIN},
{"latin", NotationSystemType::LATIN},
{"LATIN", NotationSystemType::LATIN},
Expand Down
6 changes: 3 additions & 3 deletions src/notation/measure/one_bar_allsys.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class OneBar {
mutable ListNote notes;

NotationSystemType notationName2TypeQuery(NotationSystemName name) const {
try { return notation_system_table.at(name); }
try { return NOTATION_SYSTEM_TABLE.at(name); }
catch (std::out_of_range& e) {
std::cout << "Could not identify notation system: "
<< name << " is invalid name." << "\n";
Expand All @@ -37,7 +37,7 @@ class OneBar {
}

TonalityType tonalityStr2TypeQuery(ScaleName name) const {
try { return tonality_str_type_table.at(name); }
try { return TONALITY_STR_TYPE_TABLE.at(name); }
catch (std::out_of_range& e) {
std::cout << "Could not detect tonality: "
<< name << " is invalid." << "\n";
Expand All @@ -46,7 +46,7 @@ class OneBar {
}

TonalityType relativeScaleQuery(TonalityType scale) const {
return circle_of_fifth.at(scale);
return CIRCLE_OF_FIFTH.at(scale);
}

void checkLength() const {
Expand Down
4 changes: 2 additions & 2 deletions src/notation/measure/one_bar_scisys.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class OneBar {
mutable ListNote notes;

TonalityType tonalityStr2TypeQuery(ScaleName name) const {
try { return tonality_str_type_table.at(name); }
try { return TONALITY_STR_TYPE_TABLE.at(name); }
catch (std::out_of_range& e) {
std::cout << "Could not detect tonality: "
<< name << " is invalid." << "\n";
Expand All @@ -33,7 +33,7 @@ class OneBar {
}

TonalityType relativeScaleQuery(TonalityType scale) const {
return circle_of_fifth.at(scale);
return CIRCLE_OF_FIFTH.at(scale);
}

void checkLength() const {
Expand Down
2 changes: 1 addition & 1 deletion src/notation/partition/basic_sheet.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class BasicSheet {
// Mandatory
void setScale(const std::string& scalestr) {
try {
this->tonality = tonality_str_type_table.at(scalestr);
this->tonality = TONALITY_STR_TYPE_TABLE.at(scalestr);
this->scale = scalestr;
}
catch(std::exception& e) {
Expand Down
141 changes: 141 additions & 0 deletions src/notation/partition/basic_sheet_new.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#pragma once
#include "sheet_defs.hpp"
#include "one_voice.hpp"

namespace hautbois
{

using VoiceVecPtr=std::vector<std::unique_ptr<OneVoice>>;

class BasicSheet {
protected:

const UIntValue nb_voice;
mutable Tempo tempo;
const TonalityType tonality;
const ScaleName scale;
const Meter meter;

const std::vector<InstrumentType> instrusment_list;
const std::vector<myPairClef> clefs_list;

VoiceVecPtr voices;

// append clef-at pair from token string, e.g. G-2
void appendClef(std::vector<myPairClef>& clefs_list,
const std::string& token) {
BarParserUtl parser;
TokenVector vec = parser.splitToken(token,"-");
std::string clef = vec[0];
std::string at;
if ( vec.size() == 1 ) { at = ""; }
else if ( vec.size() == 2 ) { at = vec[1]; }
else {
throw std::domain_error("Wrong format in clef pair: " + token);
}

assert(clefs_list.size() < nb_voice);
if ( clefs_list.size() >= nb_voice ) {
throw std::domain_error("Clefs already full!");
}

const UIntValue G_AT_DEFAULT = 2;
const UIntValue F_AT_DEFAULT = 4;
const UIntValue C_AT_DEFAULT = 3;

if ( clef == "G" || clef == "g" ) {
clefs_list.emplace_back( at.empty() ?
myPairClef(clef[0], G_AT_DEFAULT) :
myPairClef(clef[0], static_cast<UIntValue>(std::stoi(at)))
);
}
else if ( clef == "C" || clef == "c" ) {
clefs_list.emplace_back( at.empty() ?
myPairClef(clef[0], C_AT_DEFAULT) :
myPairClef(clef[0], static_cast<UIntValue>(std::stoi(at)))
);
}
else if ( clef == "F" || clef == "f" ) {
clefs_list.emplace_back( at.empty() ?
myPairClef(clef[0], F_AT_DEFAULT) :
myPairClef(clef[0], static_cast<UIntValue>(std::stoi(at)))
);
}
else {
throw std::domain_error("Wrong format in clef pair: " + token);
}
}

std::vector<InstrumentType>& makeClefList() {

}

void appendInstrument(std::vector<InstrumentType>& instrusment_list,
const std::string& instrument_name) {
instrusment_list.emplace_back(Instrument::str2Type(instrument_name));
}

std::vector<InstrumentType>& makeInstrumentList() {

}

/*
void checkSetUp() {
if ( nb_voice == 0 ||
scale == "unknown" ||
meter.num == 0 ) {
throw std::runtime_error("Sheet not yet set up.");
}
if ( instrusment_list.size() != nb_voice ||
clefs_list.size() != nb_voice ) {
throw std::runtime_error("Sheet not yet set up.");
}
if ( nb_voice == 0 ||
tempo == Tempo::UNKNOWN ||
tonality == TonalityType::UNKNOWN ||
scale == "unknown" ||
meter.num == 0 ) {
throw std::runtime_error("Sheet not yet set up.");
}
}
*/

public:
BasicSheet(UIntValue nbvoices) :
nb_voice { nbvoices },
tempo { Tempo::UNKNOWN },
tonality { TonalityType::UNKNOWN },
scale { "unknown" },
meter { Meter(0,1) }
{
}

void setTempo(const std::string& tempostr) {
BarParserUtl parser;
std::string tempostr_ns = parser.rmSpace(tempostr);
boost::to_lower(tempostr_ns);
try {
tempo = TEMPO_TEXT_TABLE_IT.at(tempostr_ns);
}
catch(std::exception& e) {
std::cout << "Error: invalid tempo: " << tempostr << "!\n";
}
}

OneVoice& getVoiceN(size_t n) {
assert(n < nb_voice);
if ( n > nb_voice ) {
throw std::range_error("Given value more than total voices!");
return *voices[nb_voice-1];
}
else {
return *voices[n];
}
}
};



}

0 comments on commit 751138f

Please sign in to comment.