Ticket #8860: midicfg_V4.patch
File midicfg_V4.patch, 9.4 KB (added by , 16 years ago) |
---|
-
backends/midi/windows.cpp
30 30 31 31 #include "sound/musicplugin.h" 32 32 #include "sound/mpu401.h" 33 #include "common/config-manager.h" 33 34 34 35 #include <mmsystem.h> 35 36 … … 45 46 byte _streamBuffer[256]; // SysEx blocks should be no larger than 256 bytes 46 47 HANDLE _streamEvent; 47 48 HMIDIOUT _mo; 49 UINT _dev; 48 50 bool _isOpen; 49 51 50 52 void check_error(MMRESULT result); … … 54 56 int open(); 55 57 void close(); 56 58 void send(uint32 b); 59 uint32 property(int prop, uint32 param); 57 60 void sysEx(const byte *msg, uint16 length); 58 61 }; 59 62 … … 62 65 return MERR_ALREADY_OPEN; 63 66 64 67 _streamEvent = CreateEvent(NULL, true, true, NULL); 65 MMRESULT res = midiOutOpen((HMIDIOUT *)&_mo, MIDI_MAPPER, (unsigned long)_streamEvent, 0, CALLBACK_EVENT);68 MMRESULT res = midiOutOpen((HMIDIOUT *)&_mo, _dev, (unsigned long)_streamEvent, 0, CALLBACK_EVENT); 66 69 if (res != MMSYSERR_NOERROR) { 67 70 check_error(res); 68 71 CloseHandle(_streamEvent); … … 97 100 check_error(midiOutShortMsg(_mo, u.dwData)); 98 101 } 99 102 103 uint32 MidiDriver_WIN::property(int prop, uint32 param) { 104 if (prop == PROP_DEVICE) { 105 _dev = param; 106 return 1; 107 } 108 109 return 0; 110 } 111 100 112 void MidiDriver_WIN::sysEx(const byte *msg, uint16 length) { 101 113 if (!_isOpen) 102 114 return; … … 163 175 164 176 MusicDevices WindowsMusicPlugin::getDevices() const { 165 177 MusicDevices devices; 166 // TODO: Return a different music type depending on the configuration 167 // TODO: List the available devices 168 devices.push_back(MusicDevice(this, "", MT_GM)); 178 179 uint32 numDevs = midiOutGetNumDevs(); 180 MIDIOUTCAPS tmp; 181 182 for (int i = 0; i < numDevs; i++) { 183 if (midiOutGetDevCaps(i, &tmp, sizeof(MIDIOUTCAPS)) != MMSYSERR_NOERROR) 184 break; 185 // there is no way to detect the "MusicType" so I just set it to MT_GM 186 devices.push_back(MusicDevice(this, tmp.szPname, MT_GM)); 187 } 169 188 return devices; 170 189 } 171 190 172 191 PluginError WindowsMusicPlugin::createInstance(Audio::Mixer *mixer, MidiDriver **mididriver) const { 173 192 *mididriver = new MidiDriver_WIN(); 193 uint32 dev = 0; 174 194 195 if (ConfMan.hasKey("music_driver")) { 196 const Common::String drv = ConfMan.get("music_driver"); 197 const MusicPlugin::List p = MusicMan.getPlugins(); 198 int id = 0; 199 for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) { 200 if (id != -1) { 201 id = 0; 202 MusicDevices i = (**m)->getDevices(); 203 for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) { 204 if (drv.equals(d->getCompleteName())) { 205 (*mididriver)->property(MidiDriver::PROP_DEVICE, id); 206 id = -1; 207 break; 208 } 209 id++; 210 } 211 } 212 } 213 if (id != -1) 214 // midi device turned off or whatever 215 (*mididriver)->property(MidiDriver::PROP_DEVICE, 0); 216 } else { 217 (*mididriver)->property(MidiDriver::PROP_DEVICE, 0); 218 } 219 175 220 return kNoError; 176 221 } 177 222 -
gui/options.cpp
38 38 39 39 #include "graphics/scaler.h" 40 40 41 #include "sound/m ididrv.h"41 #include "sound/musicplugin.h" 42 42 #include "sound/mixer.h" 43 43 44 44 namespace GUI { … … 167 167 // Audio options 168 168 if (_midiPopUp) { 169 169 // Music driver 170 const MidiDriverDescription *md = MidiDriver::getAvailableMidiDrivers(); 171 int i = 0; 172 const int midiDriver = 173 ConfMan.hasKey("music_driver", _domain) 174 ? MidiDriver::parseMusicDriver(ConfMan.get("music_driver", _domain)) 175 : MD_AUTO; 176 while (md->name && md->id != midiDriver) { 177 i++; 178 md++; 170 if (ConfMan.hasKey("music_driver", _domain)) { 171 const Common::String drv = ConfMan.get("music_driver", _domain); 172 const MusicPlugin::List p = MusicMan.getPlugins(); 173 int id = 0; 174 for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) { 175 if (id != -1) { 176 MusicDevices i = (**m)->getDevices(); 177 if (drv.equals((**m)->getId())) { 178 // Backwards compatibility: If the config file only 179 // stores the id we just set the default device 180 _midiPopUp->setSelected(id); 181 id = -1; 182 } else { 183 for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) { 184 if (drv.equals(d->getCompleteName())) { 185 _midiPopUp->setSelected(id); 186 id = -1; 187 break; 188 } 189 id++; 190 } 191 } 192 } 193 } 194 if (id != -1) 195 // midi device turned off or whatever 196 _midiPopUp->setSelected(0); 197 } else { 198 _midiPopUp->setSelected(0); 179 199 } 180 _midiPopUp->setSelected(md->name ? i : 0);181 200 } 182 201 183 202 if (_outputRatePopUp) { … … 302 321 // Audio options 303 322 if (_midiPopUp) { 304 323 if (_enableAudioSettings) { 305 const MidiDriverDescription *md = MidiDriver::getAvailableMidiDrivers(); 306 while (md->name && md->id != (int)_midiPopUp->getSelectedTag()) 307 md++; 308 if (md->name) 309 ConfMan.set("music_driver", md->name, _domain); 310 else 324 const MusicPlugin::List p = MusicMan.getPlugins(); 325 int id = 0; 326 for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) { 327 if (id != -1) { 328 MusicDevices i = (**m)->getDevices(); 329 for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) { 330 if (id == _midiPopUp->getSelectedTag()) { 331 ConfMan.set("music_driver", d->getCompleteName(), _domain); 332 id = -1; 333 break; 334 } 335 id++; 336 } 337 } 338 } 339 340 if (id != -1) 311 341 ConfMan.removeKey("music_driver", _domain); 312 } else {313 ConfMan.removeKey("music_driver", _domain);314 342 } 315 343 } 316 344 … … 543 571 _midiPopUp = new PopUpWidget(boss, prefix + "auMidiPopup", "Music driver:", labelWidth); 544 572 545 573 // Populate it 546 const MidiDriverDescription *md = MidiDriver::getAvailableMidiDrivers(); 547 while (md->name) { 548 _midiPopUp->appendEntry(md->description, md->id); 549 md++; 574 const MusicPlugin::List p = MusicMan.getPlugins(); 575 int id = 0; 576 for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) { 577 MusicDevices i = (**m)->getDevices(); 578 for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) 579 _midiPopUp->appendEntry(d->getCompleteName(), id++); 550 580 } 551 581 552 582 // Sample rate settings -
sound/mididrv.cpp
29 29 #include "common/system.h" 30 30 #include "common/util.h" 31 31 #include "sound/mididrv.h" 32 #include "sound/musicplugin.h" 32 33 33 34 /** Internal list of all available 'midi' drivers. */ 34 35 static const MidiDriverDescription s_musicDrivers[] = { … … 169 170 170 171 int MidiDriver::detectMusicDriver(int flags) { 171 172 // Query the selected music driver (defaults to MD_AUTO). 172 const MidiDriverDescription &md = findMusicDriver(ConfMan.get("music_driver")); 173 int musicDriver = md.id; 173 MusicDevice md = MusicMan.findMusicDevice(ConfMan.get("music_driver")); 174 174 175 // temporary "solution" since it isn't obvious to me whether 176 // detectMusicDriver() and those MidiDriverFlags will be 177 // kept or removed 175 178 // Check whether the selected music driver is compatible with the 176 // given flags. 177 if (! (md.flags & flags)) 178 musicDriver = MD_AUTO; 179 // given flags. 180 int musicDriver = MD_AUTO; 181 switch (md.getMusicType()) { 182 case MT_PCSPK: 183 case MT_PCJR: 184 musicDriver = MD_PCJR; 185 break; 186 case MT_ADLIB: 187 musicDriver = MD_ADLIB; 188 break; 189 case MT_TOWNS: 190 musicDriver = MD_TOWNS; 191 break; 192 case MT_GM: 193 case MT_MT32: 194 case MT_GS: 195 musicDriver = getDefaultMIDIDriver(); 196 break; 197 default: 198 break; 199 } 179 200 180 201 // If the selected driver is MD_AUTO, we try to determine 181 202 // a suitable and "optimal" music driver. -
sound/mididrv.h
159 159 enum { 160 160 // PROP_TIMEDIV = 1, 161 161 PROP_OLD_ADLIB = 2, 162 PROP_CHANNEL_MASK = 3 162 PROP_CHANNEL_MASK = 3, 163 PROP_DEVICE = 4 163 164 }; 164 165 165 166 /** -
sound/musicplugin.cpp
25 25 26 26 #include "sound/musicplugin.h" 27 27 28 MusicDevice MusicManager::findMusicDevice(const Common::String &str) const { 29 const MusicPlugin::List p = getPlugins(); 30 for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) { 31 MusicDevices i = (**m)->getDevices(); 32 for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) { 33 if (str.equals(d->getMusicDriverId()) || str.equals(d->getCompleteName())) 34 return *&*d; 35 } 36 } 37 return MusicDevice((MusicPluginObject const *)0, Common::String(""), (MusicType) 0); 38 } 39 28 40 MusicDevice::MusicDevice(MusicPluginObject const *musicPlugin, Common::String name, MusicType mt) : 29 41 _musicDriverName(musicPlugin->getName()), _musicDriverId(musicPlugin->getId()), 30 42 _name(name), _type(mt) { -
sound/musicplugin.h
119 119 120 120 public: 121 121 const MusicPlugin::List &getPlugins() const; 122 123 /** 124 * Find the music driver matching the given driver name/description. 125 */ 126 MusicDevice findMusicDevice(const Common::String &str) const; 122 127 }; 123 128 124 129 /** Convenience shortcut for accessing the Music manager. */