@@ -281,6 +281,7 @@ static int cmsg(int type, int verbosity_level, char *fmt, ...);
281
281
static void ctl_event (CtlEvent *e);
282
282
std::mutex event_mutex;
283
283
std::mutex data_mutex;
284
+ static bool m_loading = false ;
284
285
static bool m_running = false ;
285
286
static bool m_converting = false ;
286
287
static bool m_paused = false ;
@@ -616,9 +617,24 @@ static void reset_channels()
616
617
for (int i = 0 ; i < MAX_CHANNELS; i++)
617
618
{
618
619
midi_channels[i].events .clear ();
619
- memset (&midi_channels[i], 0 , sizeof (MIDIChannel));
620
+ midi_channels[i].key_board .reset ();
621
+ memset (midi_channels[i].instrum_name , 0 , 128 );
622
+ midi_channels[i].velocity = 0 ;
623
+ midi_channels[i].volume = 0 ;
624
+ midi_channels[i].expression = 0 ;
625
+ midi_channels[i].program = 0 ;
620
626
midi_channels[i].panning = 64 ;
621
627
midi_channels[i].pitchbend = 0x2000 ;
628
+ midi_channels[i].sustain = 0 ;
629
+ midi_channels[i].wheel = 0 ;
630
+ midi_channels[i].mute = 0 ;
631
+ midi_channels[i].bank = 0 ;
632
+ midi_channels[i].bank_lsb = 0 ;
633
+ midi_channels[i].bank_msb = 0 ;
634
+ midi_channels[i].is_drum = 0 ;
635
+ midi_channels[i].bend_mark = 0 ;
636
+ midi_channels[i].check_mute = false ;
637
+ midi_channels[i].check_solo = false ;
622
638
}
623
639
}
624
640
@@ -629,21 +645,6 @@ static void reset_events()
629
645
cuepoint_pending = 0 ;
630
646
}
631
647
632
- static std::vector<MIDI_Event>::iterator find_last (int channel, int note)
633
- {
634
- std::vector<MIDI_Event>::iterator it = midi_channels[channel].events .end ();
635
- while (it != midi_channels[channel].events .begin ())
636
- {
637
- it --;
638
- if (it->note == note && isnan (it->end_time ))
639
- {
640
- return it;
641
- }
642
- }
643
-
644
- return it;
645
- }
646
-
647
648
static void parser_events (MidiEvent * events)
648
649
{
649
650
if (events)
@@ -679,10 +680,11 @@ static void parser_events(MidiEvent * events)
679
680
}
680
681
else if (type == ME_NOTEOFF)
681
682
{
682
- std::vector<MIDI_Event>::iterator it = find_last (ch, note);
683
- if (it != midi_channels[ch].events .end ())
683
+ if (midi_channels[ch].events .size () > 0 )
684
684
{
685
- it->end_time = (float )time / play_mode->rate ;
685
+ std::vector<MIDI_Event>::iterator it = midi_channels[ch].events .end () - 1 ;
686
+ if (isnan (it->end_time ))
687
+ it->end_time = (float )time / play_mode->rate ;
686
688
}
687
689
}
688
690
else if (type == ME_ALL_NOTES_OFF)
@@ -798,12 +800,14 @@ static void ctl_event(CtlEvent *e)
798
800
switch (e->type )
799
801
{
800
802
case CTLE_NOW_LOADING: /* v1:filename */
803
+ m_loading = true ;
801
804
break ;
802
805
case CTLE_LOADING_DONE: /* v1:0=success -1=error 1=terminated */
803
806
if (e->v1 == 0 )
804
807
{
805
808
parser_events ((MidiEvent *)e->v2 );
806
809
}
810
+ m_loading = false ;
807
811
break ;
808
812
case CTLE_PLAY_START: /* v1:nsamples */
809
813
m_running = true ;
@@ -1408,7 +1412,7 @@ static void ShowMediaScopeView(int index, ImVec2 pos, ImVec2 size)
1408
1412
if (!channel_data[i].m_wave .empty ())
1409
1413
{
1410
1414
ImGui::PushID (i);
1411
- ImGui::PlotLines (" ##wave" , (float *)channel_data[i].m_wave .data , channel_data[i].m_wave .w , 0 , nullptr , -1.0 / AudioWaveScale , 1.0 / AudioWaveScale, channel_view_size, 4 , false , false );
1415
+ ImGui::PlotLinesEx (" ##wave" , (float *)channel_data[i].m_wave .data , channel_data[i].m_wave .w , 0 , nullptr , -1.0 / AudioWaveScale , 1.0 / AudioWaveScale, channel_view_size, 4 , false , false );
1412
1416
ImGui::PopID ();
1413
1417
}
1414
1418
draw_list->AddRect (channel_min, channel_max, COL_SLIDER_HANDLE, 0 );
@@ -1561,7 +1565,7 @@ static void ShowMediaScopeView(int index, ImVec2 pos, ImVec2 size)
1561
1565
if (!channel_data[i].m_fft .empty ())
1562
1566
{
1563
1567
ImGui::PushID (i);
1564
- ImGui::PlotLines (" ##fft" , (float *)channel_data[i].m_fft .data , channel_data[i].m_fft .w , 0 , nullptr , 0.0 , 1.0 / AudioFFTScale, channel_view_size, 4 , true , true );
1568
+ ImGui::PlotLinesEx (" ##fft" , (float *)channel_data[i].m_fft .data , channel_data[i].m_fft .w , 0 , nullptr , 0.0 , 1.0 / AudioFFTScale, channel_view_size, 4 , true , true );
1565
1569
ImGui::PopID ();
1566
1570
}
1567
1571
draw_list->AddRect (channel_min, channel_max, COL_SLIDER_HANDLE, 0 );
@@ -1635,7 +1639,7 @@ static void ShowMediaScopeView(int index, ImVec2 pos, ImVec2 size)
1635
1639
ImGui::PushID (i);
1636
1640
ImGui::ImMat db_mat_inv = channel_data[i].m_db .clone ();
1637
1641
db_mat_inv += 90 .f ;
1638
- ImGui::PlotLines (" ##db" , (float *)db_mat_inv.data , db_mat_inv.w , 0 , nullptr , 0 , 90 .f / AudioDBScale, channel_view_size, 4 , false , true );
1642
+ ImGui::PlotLinesEx (" ##db" , (float *)db_mat_inv.data , db_mat_inv.w , 0 , nullptr , 0 , 90 .f / AudioDBScale, channel_view_size, 4 , false , true );
1639
1643
ImGui::PopID ();
1640
1644
}
1641
1645
draw_list->AddRect (channel_min, channel_max, COL_SLIDER_HANDLE, 0 );
@@ -2102,7 +2106,7 @@ bool Application_Frame(void * handle, bool app_will_quit)
2102
2106
ImGui::SetNextWindowPos (control_pos, ImGuiCond_Always);
2103
2107
if (ImGui::BeginChild (" ##Control_Panel_Window" , control_size, false , ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoSavedSettings))
2104
2108
{
2105
- ImGui::BeginDisabled (m_running);
2109
+ ImGui::BeginDisabled (m_running || m_loading );
2106
2110
// File Dialog
2107
2111
if (ImGuiFileDialog::Instance ()->Display (" embedded" , ImGuiWindowFlags_NoCollapse, ImVec2 (0 ,0 ), ImVec2 (0 ,400 )))
2108
2112
{
@@ -2130,7 +2134,7 @@ bool Application_Frame(void * handle, bool app_will_quit)
2130
2134
ImGui::Separator ();
2131
2135
// Setting
2132
2136
// Select SoundFont
2133
- ImGui::BeginDisabled (m_running);
2137
+ ImGui::BeginDisabled (m_running || m_loading );
2134
2138
int _index = sf_index;
2135
2139
if (ImGui::Combo (" Select Sound Font" , &_index, &Funcs::ItemGetter, &sf_name_list, sf_name_list.size ()))
2136
2140
{
@@ -2303,6 +2307,7 @@ bool Application_Frame(void * handle, bool app_will_quit)
2303
2307
ImGui::BeginDisabled (!midi_is_selected);
2304
2308
ImGui::SetWindowFontScale (2.0 );
2305
2309
ImGui::SetCursorScreenPos (control_view_pos + ImVec2 (20 + time_area_x, (control_view_size.y - 64 ) / 2 ));
2310
+ ImGui::BeginDisabled (m_loading);
2306
2311
if (ImGui::Button (m_running ? (m_paused ? ICON_FA_PLAY : ICON_FA_PAUSE) : ICON_FA_PLAY " ##play_pause" , ImVec2 (64 , 64 )))
2307
2312
{
2308
2313
if (!m_running)
@@ -2324,12 +2329,13 @@ bool Application_Frame(void * handle, bool app_will_quit)
2324
2329
ImGui::SetCursorScreenPos (control_view_pos + ImVec2 (20 + time_area_x + 64 , (control_view_size.y - 64 ) / 2 ));
2325
2330
if (ImGui::Button (ICON_FA_STOP " ##stop" , ImVec2 (64 , 64 )))
2326
2331
{
2327
- if (m_running) push_event (RC_STOP, 0 );
2332
+ if (m_running || m_loading ) push_event (RC_STOP, 0 );
2328
2333
}
2329
2334
ImGui::ShowTooltipOnHover (" %s" , " Stop" );
2330
2335
ImGui::EndDisabled ();
2336
+ ImGui::EndDisabled ();
2331
2337
2332
- ImGui::BeginDisabled (m_running);
2338
+ ImGui::BeginDisabled (m_running || m_loading );
2333
2339
ImGui::SetCursorScreenPos (control_view_pos + ImVec2 (20 + time_area_x + 64 + 64 , (control_view_size.y - 64 ) / 2 ));
2334
2340
if (ImGui::Button (ICON_FA_FLOPPY_DISK " ##save_to wav" , ImVec2 (64 , 64 )))
2335
2341
{
@@ -2366,7 +2372,7 @@ bool Application_Frame(void * handle, bool app_will_quit)
2366
2372
ImGui::ColorSet tick_color = {white_color, white_color, white_color};
2367
2373
float knob_size = 84 .f ;
2368
2374
float knob_step = NAN;
2369
- ImGui::BeginDisabled (!m_running);
2375
+ ImGui::BeginDisabled (!m_running && !m_loading );
2370
2376
float main_volume = current_MFnode ? current_MFnode->master_volume : 0 ;
2371
2377
float drum_power = opt_drum_power;
2372
2378
float speed = current_MFnode ? current_MFnode->tempo_ratio : 0 ;
0 commit comments