From 2f1b5018a6a0efc901cefb0a5d31e222bdd74d6b Mon Sep 17 00:00:00 2001 From: Jono Targett Date: Fri, 24 May 2024 21:24:31 +0930 Subject: [PATCH] Take SELCAL code as command arg --- src/main.cpp | 34 ++++++++++------------------------ src/synth.cpp | 1 + 2 files changed, 11 insertions(+), 24 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index ee75fd0..2ea8abd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -10,7 +10,7 @@ int main(int argc, char** argv) { - SELCAL::Code code{"A5-CD"}; + SELCAL::Code code{argv[1]}; for (auto& group : code.getGroups()) { std::cout @@ -21,17 +21,22 @@ int main(int argc, char** argv) { Synth synth; + synth.loadSoundfont("../soundfonts/square-equaltemperament.sf2"); + //synth.loadSoundfont("../soundfonts/TimGM6mb.sf2"); + synth.loadSoundfont("../soundfonts/GU-1.471.sf2"); + /* for(int i = 1; i < argc; ++i) { synth.loadSoundfont(argv[i]); } + */ for (const Synth::Program& program : synth.getPrograms()) { std::cout << program.name << " " << program.soundfontId << ":(" << program.bankNumber << ", " << program.programNumber << ")" << std::endl; - if (program.name == "Square Wave") { + if (program.name == "Night Vision") { std::cout << "Loading program!" << std::endl; synth.loadProgram(program); } @@ -83,12 +88,6 @@ int main(int argc, char** argv) { constexpr double MIDI_CENT_SCALE = 100.0; const int keyIndex = static_cast(pair.first); tunings[keyIndex] = frequencyToMidi(pair.second) * MIDI_CENT_SCALE; - - std::cout - << magic_enum::enum_name(pair.first) << " = " - << pair.second << " Hz " - << " or MIDI key " << frequencyToMidi(pair.second) * MIDI_CENT_SCALE - << std::endl; } fluid_synth_t* raw_synth = synth.getSynth(); @@ -101,8 +100,8 @@ int main(int argc, char** argv) { std::cout << "Set tuning: " << (success ? "success" : "failed") << std::endl; for (auto& group : code.getGroups()) { - fluid_synth_noteon(raw_synth, 0, static_cast(group[0]), 100); - fluid_synth_noteon(raw_synth, 1, static_cast(group[1]), 100); + fluid_synth_noteon(raw_synth, 0, static_cast(group[0]), 127); + fluid_synth_noteon(raw_synth, 1, static_cast(group[1]), 127); std::this_thread::sleep_for(1s); // Silence between tone groups @@ -110,18 +109,5 @@ int main(int argc, char** argv) { std::this_thread::sleep_for(200ms); } - /* - success = synth.resetTuning(); - std::cout << "Set tuning: " << (success ? "success" : "failed") << std::endl; - - for (auto& group : code.getGroups()) { - fluid_synth_noteon(raw_synth, 0, static_cast(group[0]), 100); - fluid_synth_noteon(raw_synth, 1, static_cast(group[1]), 100); - std::this_thread::sleep_for(1s); - - // Silence between tone groups - fluid_synth_all_notes_off(raw_synth, ALL_CHANNELS); - std::this_thread::sleep_for(200ms); - } - */ + std::this_thread::sleep_for(500ms); } diff --git a/src/synth.cpp b/src/synth.cpp index 22e4277..b651117 100644 --- a/src/synth.cpp +++ b/src/synth.cpp @@ -65,6 +65,7 @@ bool Synth::loadSoundfont(const std::string& filepath) { bool Synth::loadProgram(const Program& program) { // TODO JMT: fix this fluid_synth_program_select(synth, 0, program.soundfontId, program.bankNumber, program.programNumber); + fluid_synth_program_select(synth, 1, program.soundfontId, program.bankNumber, program.programNumber); return true; }