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

Function init

TheForceEngine/TFE_Audio/midiPlayer.cpp:100–153  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

98 };
99
100 bool init(s32 midiDeviceIndex, MidiDeviceType type)
101 {
102 TFE_System::logWrite(LOG_MSG, "Startup", "TFE_MidiPlayer::init");
103 bool res = false;
104
105 s_midiThreadMutex = SDL_CreateMutex();
106 if (!s_midiThreadMutex)
107 {
108 TFE_System::logWrite(LOG_ERROR, "Midi", "cannot initialize SDL midi thread mutex");
109 return false;
110 }
111
112 s_deviceChangeMutex = SDL_CreateMutex();
113 if (!s_deviceChangeMutex)
114 {
115 TFE_System::logWrite(LOG_ERROR, "Midi", "cannot initialize SDL device change mutex");
116 return false;
117 }
118
119 SDL_LockMutex(s_deviceChangeMutex);
120 {
121 allocateMidiDevice(type);
122 if (s_midiDevice)
123 {
124 res = true;
125 if (!s_midiDevice->selectOutput(midiDeviceIndex))
126 {
127 if (!s_midiDevice->selectOutput(0))
128 {
129 TFE_System::logWrite(LOG_ERROR, "Midi", "Cannot load soundfont '%s'.", "SoundFonts/SYNTHGM.sf2");
130 res = false;
131 }
132 }
133 }
134 }
135 SDL_UnlockMutex(s_deviceChangeMutex);
136
137 s_runMusicThread.store(true);
138 s_thread = SDL_CreateThread(midiUpdateFunc, "TFE_MidiThread", nullptr);
139 if (!s_thread)
140 {
141 TFE_System::logWrite(LOG_ERROR, "Midi", "cannot create Midi Thread!");
142 res = false;
143 }
144
145 CCMD("setMusicVolume", setMusicVolumeConsole, 1, "Sets the music volume, range is 0.0 to 1.0");
146 CCMD("getMusicVolume", getMusicVolumeConsole, 0, "Get the current music volume where 0 = silent, 1 = maximum.");
147
148 TFE_Settings_Sound* soundSettings = TFE_Settings::getSoundSettings();
149 setVolume(soundSettings->musicVolume);
150 setMaximumNoteLength();
151
152 return res && s_thread;
153 }
154
155 void destroy()
156 {

Callers

nothing calls this directly

Calls 6

logWriteFunction · 0.85
allocateMidiDeviceFunction · 0.85
getSoundSettingsFunction · 0.85
setMaximumNoteLengthFunction · 0.85
setVolumeFunction · 0.70
selectOutputMethod · 0.45

Tested by

no test coverage detected