MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / midiUpdateFunc

Function midiUpdateFunc

TheForceEngine/TFE_Audio/midiPlayer.cpp:473–540  ·  view source on GitHub ↗

Thread Function

Source from the content-addressed store, hash-verified

471
472 // Thread Function
473 int midiUpdateFunc(void* userData)
474 {
475 bool runThread = true;
476 bool wasPlaying = false;
477 bool isPlaying = false;
478 bool isPaused = false;
479 s32 loopStart = -1;
480 u64 localTime = 0;
481 u64 localTimeCallback = 0;
482 f64 dt = 0.0;
483 while (runThread)
484 {
485 SDL_LockMutex(s_midiThreadMutex);
486
487 // Read from the command buffer.
488 MidiCmd* midiCmd = s_midiCmdBuffer;
489 for (u32 i = 0; i < s_midiCmdCount; i++, midiCmd++)
490 {
491 switch (midiCmd->cmd)
492 {
493 case MIDI_PAUSE:
494 {
495 localTimeCallback = 0;
496 isPaused = true;
497 stopAllNotes();
498 } break;
499 case MIDI_RESUME:
500 {
501 isPaused = false;
502 } break;
503 case MIDI_CHANGE_VOL:
504 {
505 s_masterVolume = midiCmd->newVolume;
506 s_masterVolumeScaled = s_masterVolume * c_musicVolumeScale;
507 changeVolume();
508 } break;
509 case MIDI_STOP_NOTES:
510 {
511 stopAllNotes();
512 // Reset callback time.
513 localTimeCallback = 0;
514 s_midiCallback.accumulator = 0.0;
515 } break;
516 }
517 }
518 s_midiCmdCount = 0;
519
520 // Process the midi callback, if it exists.
521 if (s_midiCallback.callback && !isPaused)
522 {
523 s_midiCallback.accumulator += TFE_System::updateThreadLocal(&localTimeCallback);
524 while (s_midiCallback.callback && s_midiCallback.accumulator >= s_midiCallback.timeStep)
525 {
526 s_midiCallback.callback();
527 s_midiCallback.accumulator -= s_midiCallback.timeStep;
528 s_curNoteTime += s_midiCallback.timeStep;
529 }
530

Callers

nothing calls this directly

Calls 5

stopAllNotesFunction · 0.85
changeVolumeFunction · 0.85
updateThreadLocalFunction · 0.85
detectHangingNotesFunction · 0.85
loadMethod · 0.45

Tested by

no test coverage detected