Skip to content

Commit

Permalink
Preload instruments on File load
Browse files Browse the repository at this point in the history
  • Loading branch information
brummer10 committed Mar 22, 2024
1 parent 0b1d0d2 commit d49135a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/MidiKeyBoard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,6 @@ void XKeyBoard::read_config() {
else if (key.compare("[midi_through]") == 0) xjack->midi_through = std::stoi(value);
else if (key.compare("[mchannel]") == 0) mchannel = std::stoi(value);
else if (key.compare("[velocity]") == 0) velocity = std::stoi(value);
else if (key.compare("[bpm]") == 0) mbpm = std::stoi(value);
else if (key.compare("[song_bpm]") == 0) song_bpm = std::stoi(value);
else if (key.compare("[filepath]") == 0) filepath = remove_sub(line, "[filepath] ");
else if (key.compare("[scala_filepath]") == 0) scala_filepath = remove_sub(line, "[scala_filepath] ");
else if (key.compare("[octave]") == 0) octave = std::stoi(value);
Expand Down Expand Up @@ -387,8 +385,6 @@ void XKeyBoard::save_config() {
outfile << "[midi_through] " << xjack->midi_through << std::endl;
outfile << "[mchannel] " << mchannel << std::endl;
outfile << "[velocity] " << velocity << std::endl;
outfile << "[bpm] " << mbpm << std::endl;
outfile << "[song_bpm] " << song_bpm << std::endl;
outfile << "[filepath] " << filepath << std::endl;
outfile << "[scala_filepath] " << scala_filepath << std::endl;
outfile << "[octave] " << octave << std::endl;
Expand Down Expand Up @@ -1794,6 +1790,15 @@ void XKeyBoard::dialog_load_response(void *w_, void* user_data) {
_("Couldn't load file, is that a MIDI file?"),NULL);
XSetTransientForHint(xjmkb->win->app->dpy, dia->widget, xjmkb->win->widget);
} else {
if (xjmkb->xsynth->synth_is_active()) {
for(std::vector<mamba::MidiEvent>::iterator i = xjmkb->xjack->rec.play[0].begin(); i != xjmkb->xjack->rec.play[0].end(); ++i) {
if (((*i).buffer[0] & 0xf0) == 0xB0 && ((*i).buffer[1]== 32 || (*i).buffer[1]== 0)) {
xjmkb->mmessage->send_midi_cc((*i).buffer[0], (*i).buffer[1], (*i).buffer[2], 3, true);
} else if (((*i).buffer[0] & 0xf0) == 0xC0 ) {
xjmkb->mmessage->send_midi_cc((*i).buffer[0], (*i).buffer[1], 0, 2, true);
}
}
}
xjmkb->recent_file_manager(*(char**)user_data);
std::string file(basename(*(char**)user_data));
for(int i = 1;i<16;i++)
Expand All @@ -1812,6 +1817,7 @@ void XKeyBoard::dialog_load_response(void *w_, void* user_data) {
xjmkb->time_line->label = xjmkb->time_line->input_label;
expose_widget(xjmkb->time_line);
adj_set_value(xjmkb->play->adj, play);
if (xjmkb->xsynth->synth_is_active()) xjmkb->rebuild_instrument_list();
}
}
}
Expand Down Expand Up @@ -3294,8 +3300,9 @@ void XKeyBoard::rebuild_instrument_list() {
}

int i = xsynth->get_instrument_for_channel(mchannel);
if ( i >-1)
if ( i >-1) {
combobox_set_active_entry(fs_instruments, i);
}
}

//static
Expand Down
5 changes: 5 additions & 0 deletions src/XSynth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,11 @@ void XSynth::init_synth() {
setup_tunnings_for_channelemap();
}

int XSynth::synth_send_cc(int channel, int num, int value) {
if (!synth) return -1;
return fluid_synth_cc(synth, channel, num, value);
}

int XSynth::load_soundfont(const char *path) {
if (sf_id != -1) fluid_synth_sfunload(synth, sf_id, 0);
sf_id = fluid_synth_sfload(synth, path, 1);
Expand Down
1 change: 1 addition & 0 deletions src/XSynth.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class XSynth {

void setup(unsigned int SampleRate, const char *instance_name);
void init_synth();
int synth_send_cc(int channel, int num, int value);
int synth_is_active() {return synth ? 1 : 0;}
int load_soundfont(const char *path);
void print_soundfont();
Expand Down

0 comments on commit d49135a

Please sign in to comment.