Ticket #8860: midicfg_V4.patch

File midicfg_V4.patch, 9.4 KB (added by athrxx, 16 years ago)
  • backends/midi/windows.cpp

     
    3030
    3131#include "sound/musicplugin.h"
    3232#include "sound/mpu401.h"
     33#include "common/config-manager.h"
    3334
    3435#include <mmsystem.h>
    3536
     
    4546        byte _streamBuffer[256];        // SysEx blocks should be no larger than 256 bytes
    4647        HANDLE _streamEvent;
    4748        HMIDIOUT _mo;
     49        UINT _dev;
    4850        bool _isOpen;
    4951
    5052        void check_error(MMRESULT result);
     
    5456        int open();
    5557        void close();
    5658        void send(uint32 b);
     59        uint32 property(int prop, uint32 param);
    5760        void sysEx(const byte *msg, uint16 length);
    5861};
    5962
     
    6265                return MERR_ALREADY_OPEN;
    6366
    6467        _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);
    6669        if (res != MMSYSERR_NOERROR) {
    6770                check_error(res);
    6871                CloseHandle(_streamEvent);
     
    97100        check_error(midiOutShortMsg(_mo, u.dwData));
    98101}
    99102
     103uint32 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
    100112void MidiDriver_WIN::sysEx(const byte *msg, uint16 length) {
    101113        if (!_isOpen)
    102114                return;
     
    163175
    164176MusicDevices WindowsMusicPlugin::getDevices() const {
    165177        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        }
    169188        return devices;
    170189}
    171190
    172191PluginError WindowsMusicPlugin::createInstance(Audio::Mixer *mixer, MidiDriver **mididriver) const {
    173192        *mididriver = new MidiDriver_WIN();
     193        uint32 dev = 0;
    174194
     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
    175220        return kNoError;
    176221}
    177222
  • gui/options.cpp

     
    3838
    3939#include "graphics/scaler.h"
    4040
    41 #include "sound/mididrv.h"
     41#include "sound/musicplugin.h"
    4242#include "sound/mixer.h"
    4343
    4444namespace GUI {
     
    167167        // Audio options
    168168        if (_midiPopUp) {
    169169                // 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);
    179199                }
    180                 _midiPopUp->setSelected(md->name ? i : 0);
    181200        }
    182201
    183202        if (_outputRatePopUp) {
     
    302321                // Audio options
    303322                if (_midiPopUp) {
    304323                        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)
    311341                                        ConfMan.removeKey("music_driver", _domain);
    312                         } else {
    313                                 ConfMan.removeKey("music_driver", _domain);
    314342                        }
    315343                }
    316344
     
    543571        _midiPopUp = new PopUpWidget(boss, prefix + "auMidiPopup", "Music driver:", labelWidth);
    544572
    545573        // 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++);
    550580        }
    551581
    552582        // Sample rate settings
  • sound/mididrv.cpp

     
    2929#include "common/system.h"
    3030#include "common/util.h"
    3131#include "sound/mididrv.h"
     32#include "sound/musicplugin.h"
    3233
    3334/** Internal list of all available 'midi' drivers. */
    3435static const MidiDriverDescription s_musicDrivers[] = {
     
    169170
    170171int MidiDriver::detectMusicDriver(int flags) {
    171172        // 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"));
    174174
     175        // temporary "solution" since it isn't obvious to me whether
     176        // detectMusicDriver() and those MidiDriverFlags will be
     177        // kept or removed
    175178        // 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        }
    179200
    180201        // If the selected driver is MD_AUTO, we try to determine
    181202        // a suitable and "optimal" music driver.
  • sound/mididrv.h

     
    159159        enum {
    160160//              PROP_TIMEDIV = 1,
    161161                PROP_OLD_ADLIB = 2,
    162                 PROP_CHANNEL_MASK = 3
     162                PROP_CHANNEL_MASK = 3,
     163                PROP_DEVICE = 4
    163164        };
    164165
    165166        /**
  • sound/musicplugin.cpp

     
    2525
    2626#include "sound/musicplugin.h"
    2727
     28MusicDevice 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
    2840MusicDevice::MusicDevice(MusicPluginObject const *musicPlugin, Common::String name, MusicType mt) :
    2941        _musicDriverName(musicPlugin->getName()), _musicDriverId(musicPlugin->getId()),
    3042        _name(name), _type(mt) {
  • sound/musicplugin.h

     
    119119
    120120public:
    121121        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;
    122127};
    123128
    124129/** Convenience shortcut for accessing the Music manager. */