Ticket #8860: midicfg_New.patch

File midicfg_New.patch, 92.5 KB (added by athrxx, 10 years ago)

latest version

  • backends/midi/alsa.cpp

     
    269269        }
    270270
    271271        MusicDevices getDevices() const;
    272         Common::Error createInstance(MidiDriver **mididriver) const;
     272        Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
    273273};
    274274
    275275#define perm_ok(pinfo,bits) ((snd_seq_port_info_get_capability(pinfo) & (bits)) == (bits))
     
    315315        return devices;
    316316}
    317317
    318 Common::Error AlsaMusicPlugin::createInstance(MidiDriver **mididriver) const {
     318Common::Error AlsaMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
    319319        *mididriver = new MidiDriver_ALSA();
    320320
    321321        return Common::kNoError;
    322322}
    323323
    324 MidiDriver *MidiDriver_ALSA_create() {
    325         MidiDriver *mididriver;
    326 
    327         AlsaMusicPlugin p;
    328         p.createInstance(&mididriver);
    329 
    330         return mididriver;
    331 }
    332 
    333324//#if PLUGIN_ENABLED_DYNAMIC(ALSA)
    334325        //REGISTER_PLUGIN_DYNAMIC(ALSA, PLUGIN_TYPE_MUSIC, AlsaMusicPlugin);
    335326//#else
  • backends/midi/camd.cpp

     
    177177        }
    178178
    179179        MusicDevices getDevices() const;
    180         Common::Error createInstance(MidiDriver **mididriver) const;
     180        Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
    181181};
    182182
    183183MusicDevices CamdMusicPlugin::getDevices() const {
     
    188188        return devices;
    189189}
    190190
    191 Common::Error CamdMusicPlugin::createInstance(MidiDriver **mididriver) const {
     191Common::Error CamdMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
    192192        *mididriver = new MidiDriver_CAMD();
    193193
    194194        return Common::kNoError;
    195195}
    196196
    197 MidiDriver *MidiDriver_CAMD_create() {
    198         MidiDriver *mididriver;
    199 
    200         CamdMusicPlugin p;
    201         p.createInstance(&mididriver);
    202 
    203         return mididriver;
    204 }
    205 
    206197//#if PLUGIN_ENABLED_DYNAMIC(CAMD)
    207198        //REGISTER_PLUGIN_DYNAMIC(CAMD, PLUGIN_TYPE_MUSIC, CamdMusicPlugin);
    208199//#else
  • backends/midi/coreaudio.cpp

     
    218218        }
    219219
    220220        MusicDevices getDevices() const;
    221         Common::Error createInstance(MidiDriver **mididriver) const;
     221        Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
    222222};
    223223
    224224MusicDevices CoreAudioMusicPlugin::getDevices() const {
     
    229229        return devices;
    230230}
    231231
    232 Common::Error CoreAudioMusicPlugin::createInstance(MidiDriver **mididriver) const {
     232Common::Error CoreAudioMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
    233233        *mididriver = new MidiDriver_CORE();
    234234
    235235        return Common::kNoError;
    236236}
    237237
    238 MidiDriver *MidiDriver_CORE_create() {
    239         MidiDriver *mididriver;
    240 
    241         CoreAudioMusicPlugin p;
    242         p.createInstance(&mididriver);
    243 
    244         return mididriver;
    245 }
    246 
    247238//#if PLUGIN_ENABLED_DYNAMIC(COREAUDIO)
    248239        //REGISTER_PLUGIN_DYNAMIC(COREAUDIO, PLUGIN_TYPE_MUSIC, CoreAudioMusicPlugin);
    249240//#else
  • backends/midi/coremidi.cpp

     
    190190        }
    191191
    192192        MusicDevices getDevices() const;
    193         Common::Error createInstance(MidiDriver **mididriver) const;
     193        Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
    194194};
    195195
    196196MusicDevices CoreMIDIMusicPlugin::getDevices() const {
     
    201201        return devices;
    202202}
    203203
    204 Common::Error CoreMIDIMusicPlugin::createInstance(MidiDriver **mididriver) const {
     204Common::Error CoreMIDIMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
    205205        *mididriver = new MidiDriver_CoreMIDI();
    206206
    207207        return Common::kNoError;
    208208}
    209209
    210 MidiDriver *MidiDriver_CoreMIDI_create() {
    211         MidiDriver *mididriver;
    212 
    213         CoreMIDIMusicPlugin p;
    214         p.createInstance(&mididriver);
    215 
    216         return mididriver;
    217 }
    218 
    219210//#if PLUGIN_ENABLED_DYNAMIC(COREMIDI)
    220211        //REGISTER_PLUGIN_DYNAMIC(COREMIDI, PLUGIN_TYPE_MUSIC, CoreMIDIMusicPlugin);
    221212//#else
  • backends/midi/dmedia.cpp

     
    199199        }
    200200
    201201        MusicDevices getDevices() const;
    202         Common::Error createInstance(MidiDriver **mididriver) const;
     202        Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
    203203};
    204204
    205205MusicDevices DMediaMusicPlugin::getDevices() const {
     
    224224        return devices;
    225225}
    226226
    227 Common::Error DMediaMusicPlugin::createInstance(MidiDriver **mididriver) const {
     227Common::Error DMediaMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
    228228        *mididriver = new MidiDriver_DMEDIA();
    229229
    230230        return Common::kNoError;
    231231}
    232232
    233 MidiDriver *MidiDriver_DMEDIA_create() {
    234         MidiDriver *mididriver;
    235 
    236         DMediaMusicPlugin p;
    237         p.createInstance(&mididriver);
    238 
    239         return mididriver;
    240 }
    241 
    242233//#if PLUGIN_ENABLED_DYNAMIC(DMEDIA)
    243234        //REGISTER_PLUGIN_DYNAMIC(DMEDIA, PLUGIN_TYPE_MUSIC, DMediaMusicPlugin);
    244235//#else
  • backends/midi/seq.cpp

     
    184184        }
    185185
    186186        MusicDevices getDevices() const;
    187         Common::Error createInstance(MidiDriver **mididriver) const;
     187        Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
    188188};
    189189
    190190MusicDevices SeqMusicPlugin::getDevices() const {
     
    195195        return devices;
    196196}
    197197
    198 Common::Error SeqMusicPlugin::createInstance(MidiDriver **mididriver) const {
     198Common::Error SeqMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
    199199        *mididriver = new MidiDriver_SEQ();
    200200
    201201        return Common::kNoError;
    202202}
    203203
    204 MidiDriver *MidiDriver_SEQ_create() {
    205         MidiDriver *mididriver;
    206 
    207         SeqMusicPlugin p;
    208         p.createInstance(&mididriver);
    209 
    210         return mididriver;
    211 }
    212 
    213204//#if PLUGIN_ENABLED_DYNAMIC(SEQ)
    214205        //REGISTER_PLUGIN_DYNAMIC(SEQ, PLUGIN_TYPE_MUSIC, SeqMusicPlugin);
    215206//#else
  • backends/midi/stmidi.cpp

     
    127127        }
    128128
    129129        MusicDevices getDevices() const;
    130         Common::Error createInstance(MidiDriver **mididriver)
    131  const;
     130                Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
    132131};
    133132
    134133MusicDevices StMidiMusicPlugin::getDevices() const {
     
    139138        return devices;
    140139}
    141140
    142 Common::Error StMidiMusicPlugin::createInstance(MidiDriver **mididriver) const {
     141Common::Error StMidiMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
    143142        *mididriver = new MidiDriver_STMIDI();
    144143
    145144        return Common::kNoError;
    146145}
    147146
    148 MidiDriver *MidiDriver_STMIDI_create() {
    149         MidiDriver *mididriver;
    150 
    151         StMidiMusicPlugin p;
    152         p.createInstance(&mididriver);
    153 
    154         return mididriver;
    155 }
    156 
    157147//#if PLUGIN_ENABLED_DYNAMIC(STMIDI)
    158148        //REGISTER_PLUGIN_DYNAMIC(STMIDI, PLUGIN_TYPE_MUSIC, StMidiMusicPlugin);
    159149//#else
  • backends/midi/timidity.cpp

     
    530530        }
    531531
    532532        MusicDevices getDevices() const;
    533         Common::Error createInstance(MidiDriver **mididriver) const;
     533        Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
    534534};
    535535
    536536MusicDevices TimidityMusicPlugin::getDevices() const {
     
    539539        return devices;
    540540}
    541541
    542 Common::Error TimidityMusicPlugin::createInstance(MidiDriver **mididriver) const {
     542Common::Error TimidityMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
    543543        *mididriver = new MidiDriver_TIMIDITY();
    544544
    545545        return Common::kNoError;
    546546}
    547547
    548 MidiDriver *MidiDriver_TIMIDITY_create() {
    549         MidiDriver *mididriver;
    550 
    551         TimidityMusicPlugin p;
    552         p.createInstance(&mididriver);
    553 
    554         return mididriver;
    555 }
    556 
    557548//#if PLUGIN_ENABLED_DYNAMIC(TIMIDITY)
    558549        //REGISTER_PLUGIN_DYNAMIC(TIMIDITY, PLUGIN_TYPE_MUSIC, TimidityMusicPlugin);
    559550//#else
  • 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
     
    4647        HANDLE _streamEvent;
    4748        HMIDIOUT _mo;
    4849        bool _isOpen;
     50        int _device;
    4951
    5052        void check_error(MMRESULT result);
    5153
    5254public:
    53         MidiDriver_WIN() : _isOpen(false) { }
     55        MidiDriver_WIN(int deviceIndex) : _isOpen(false), _device(deviceIndex) { }
    5456        int open();
    5557        void close();
    5658        void send(uint32 b);
     
    6264                return MERR_ALREADY_OPEN;
    6365
    6466        _streamEvent = CreateEvent(NULL, true, true, NULL);
    65         MMRESULT res = midiOutOpen((HMIDIOUT *)&_mo, MIDI_MAPPER, (DWORD_PTR)_streamEvent, 0, CALLBACK_EVENT);
     67        MMRESULT res = midiOutOpen((HMIDIOUT *)&_mo, _device, (DWORD_PTR)_streamEvent, 0, CALLBACK_EVENT);
    6668        if (res != MMSYSERR_NOERROR) {
    6769                check_error(res);
    6870                CloseHandle(_streamEvent);
     
    158160        }
    159161
    160162        MusicDevices getDevices() const;
    161         Common::Error createInstance(MidiDriver **mididriver) const;
     163        Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
    162164};
    163165
    164166MusicDevices WindowsMusicPlugin::getDevices() const {
    165167        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));
     168        int numDevs = midiOutGetNumDevs();
     169        MIDIOUTCAPS tmp;
     170
     171        for (int i = 0; i < numDevs; i++) {
     172                if (midiOutGetDevCaps(i, &tmp, sizeof(MIDIOUTCAPS)) != MMSYSERR_NOERROR)
     173                        break;
     174                // There is no way to detect the "MusicType" so I just set it to MT_GM
     175                // The user will have to manually select his MT32 type device and his GM type device.
     176                devices.push_back(MusicDevice(this, tmp.szPname, MT_GM));
     177        }
    169178        return devices;
    170179}
    171180
    172 Common::Error WindowsMusicPlugin::createInstance(MidiDriver **mididriver) const {
    173         *mididriver = new MidiDriver_WIN();
     181Common::Error WindowsMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle dev) const {
     182        int devIndex = 0;
     183        bool found = false;
    174184
     185        if (dev) {
     186                MusicDevices i = getDevices();
     187                for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) {
     188                        if (d->getCompleteId().equals(MidiDriver::getDeviceString(dev, MidiDriver::kDeviceId))) {
     189                                found = true;
     190                                break;
     191                        }
     192                        devIndex++;
     193                }
     194        }
     195
     196        *mididriver = new MidiDriver_WIN(found ? devIndex : 0);
    175197        return Common::kNoError;
    176198}
    177199
    178 MidiDriver *MidiDriver_WIN_create() {
    179         MidiDriver *mididriver;
    180 
    181         WindowsMusicPlugin p;
    182         p.createInstance(&mididriver);
    183 
    184         return mididriver;
    185 }
    186 
    187200//#if PLUGIN_ENABLED_DYNAMIC(WINDOWS)
    188201        //REGISTER_PLUGIN_DYNAMIC(WINDOWS, PLUGIN_TYPE_MUSIC, WindowsMusicPlugin);
    189202//#else
  • backends/midi/ypa1.cpp

     
    117117        }
    118118
    119119        MusicDevices getDevices() const;
    120         Common::Error createInstance(MidiDriver **mididriver) const;
     120        Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
    121121};
    122122
    123123MusicDevices YamahaPa1MusicPlugin::getDevices() const {
     
    128128        return devices;
    129129}
    130130
    131 Common::Error YamahaPa1MusicPlugin::createInstance(MidiDriver **mididriver) const {
     131Common::Error YamahaPa1MusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
    132132        *mididriver = new MidiDriver_YamahaPa1();
    133133
    134134        return Common::kNoError;
    135135}
    136136
    137 MidiDriver *MidiDriver_YamahaPa1_create() {
    138         MidiDriver *mididriver;
    139 
    140         YamahaPa1MusicPlugin p;
    141         p.createInstance(&mididriver);
    142 
    143         return mididriver;
    144 }
    145 
    146137//#if PLUGIN_ENABLED_DYNAMIC(YPA1)
    147138        //REGISTER_PLUGIN_DYNAMIC(YPA1, PLUGIN_TYPE_MUSIC, YamahaPa1MusicPlugin);
    148139//#else
  • backends/midi/zodiac.cpp

     
    135135        }
    136136
    137137        MusicDevices getDevices() const;
    138         Common::Error createInstance(MidiDriver **mididriver) const;
     138        Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
    139139};
    140140
    141141MusicDevices ZodiacMusicPlugin::getDevices() const {
     
    146146        return devices;
    147147}
    148148
    149 Common::Error ZodiacMusicPlugin::createInstance(MidiDriver **mididriver) const {
     149Common::Error ZodiacMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
    150150        *mididriver = new MidiDriver_Zodiac();
    151151
    152152        return Common::kNoError;
    153153}
    154154
    155 MidiDriver *MidiDriver_Zodiac_create() {
    156         MidiDriver *mididriver;
    157 
    158         ZodiacMusicPlugin p;
    159         p.createInstance(&mididriver);
    160 
    161         return mididriver;
    162 }
    163 
    164155//#if PLUGIN_ENABLED_DYNAMIC(ZODIAC)
    165156        //REGISTER_PLUGIN_DYNAMIC(ZODIAC, PLUGIN_TYPE_MUSIC, ZodiacMusicPlugin);
    166157//#else
  • base/commandLine.cpp

     
    364364                        END_OPTION
    365365
    366366                        DO_OPTION('e', "music-driver")
    367                                 if (MidiDriver::findMusicDriver(option) == 0)
     367                                if (MidiDriver::getMusicType(MidiDriver::getDeviceHandle(option)) == MT_NULL)
    368368                                        usage("Unrecognized music driver '%s'", option);
    369369                        END_OPTION
    370370
  • base/plugins.cpp

     
    167167                // Music plugins
    168168                // TODO: Use defines to disable or enable each MIDI driver as a
    169169                // static/dynamic plugin, like it's done for the engines
     170                LINK_PLUGIN(AUTO)
    170171                LINK_PLUGIN(NULL)
    171172                #if defined(WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
    172173                LINK_PLUGIN(WINDOWS)
  • common/util.cpp

     
    305305        { GUIO_MIDIPCJR,                "midiPCJr" },
    306306        { GUIO_MIDIADLIB,               "midiAdLib" },
    307307        { GUIO_MIDITOWNS,       "midiTowns" },
    308         { GUIO_MIDI,                            "midiMidi" },
     308        { GUIO_MIDIMT32,                        "midiMt32" },
     309        { GUIO_MIDIGM,                          "midiGM" },
    309310
    310311        { GUIO_NONE, 0 }
    311312};
  • common/util.h

     
    223223        GUIO_MIDICMS            = (1 << 7),
    224224        GUIO_MIDIPCJR           = (1 << 8),
    225225        GUIO_MIDIADLIB          = (1 << 9),
    226         GUIO_MIDITOWNS  = (1 << 10),
    227         GUIO_MIDI                               = (1 << 11)
     226        GUIO_MIDITOWNS          = (1 << 10),
     227        GUIO_MIDIMT32           = (1 << 11),
     228        GUIO_MIDIGM                     = (1 << 12)
    228229};
    229230
    230231bool checkGameGUIOption(GameGUIOption option, const String &str);
  • engines/agi/agi.cpp

     
    583583        } else if (getPlatform() == Common::kPlatformCoCo3) {
    584584                _soundemu = SOUND_EMU_COCO3;
    585585        } else {
    586                 switch (MidiDriver::detectMusicDriver(MDT_PCSPK | MDT_PCJR | MDT_ADLIB | MDT_MIDI)) {
    587                 case MD_PCSPK:
     586                switch (MidiDriver::getMusicType(MidiDriver::detectDevice(MDT_PCSPK))) {
     587                case MT_PCSPK:
    588588                        _soundemu = SOUND_EMU_PC;
    589589                        break;
    590                 case MD_PCJR:
     590                case MT_PCJR:
    591591                        _soundemu = SOUND_EMU_PCJR;
    592592                        break;
    593                 case MD_ADLIB:
     593                case MT_ADLIB:
    594594                        _soundemu = SOUND_EMU_NONE;
    595595                        break;
    596596                default:
  • engines/agi/preagi.cpp

     
    6868        //       drivers, and I'm not sure what they are. For now, they might
    6969        //       as well be called "PC Speaker" and "Not PC Speaker".
    7070
    71         switch (MidiDriver::detectMusicDriver(MDT_PCSPK)) {
    72         case MD_PCSPK:
     71        switch (MidiDriver::getMusicType(MidiDriver::detectDevice(MDT_PCSPK))) {
     72        case MT_PCSPK:
    7373                _soundemu = SOUND_EMU_PC;
    7474                break;
    7575        default:
  • engines/agi/sound_midi.cpp

     
    7171}
    7272
    7373SoundGenMIDI::SoundGenMIDI(AgiEngine *vm, Audio::Mixer *pMixer) : SoundGen(vm, pMixer), _parser(0), _isPlaying(false), _passThrough(false), _isGM(false) {
    74         MidiDriverType midiDriver = MidiDriver::detectMusicDriver(MDT_MIDI | MDT_ADLIB);
    75         _driver = MidiDriver::createMidi(midiDriver);
     74        DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB);
     75        _driver = MidiDriver::createMidi(dev);
    7676
    7777        memset(_channel, 0, sizeof(_channel));
    7878        memset(_channelVolume, 255, sizeof(_channelVolume));
  • engines/agos/agos.cpp

     
    557557                (getPlatform() == Common::kPlatformPC)) {
    558558
    559559                // Setup midi driver
    560                 MidiDriverType midiDriver = MidiDriver::detectMusicDriver(MDT_ADLIB | MDT_MIDI);
    561                 _nativeMT32 = ((midiDriver == MD_MT32) || ConfMan.getBool("native_mt32"));
     560                MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_ADLIB | MDT_MIDI | MDT_PREFER_MIDI | (getGameType() == GType_SIMON1 ? MDT_PREFER_MT32 : MDT_PREFER_GM));
     561                _nativeMT32 = ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32"));
    562562
    563                 _driver = MidiDriver::createMidi(midiDriver);
     563                _driver = MidiDriver::createMidi(dev);
    564564
    565565                if (_nativeMT32) {
    566566                        _driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
  • engines/draci/draci.cpp

     
    127127        _dubbingArchive = new SoundArchive(dubbingPath, kDubbingFrequency);
    128128        _sound = new Sound(_mixer);
    129129
    130         MidiDriverType midiDriver = MidiDriver::detectMusicDriver(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
    131         bool native_mt32 = ((midiDriver == MD_MT32) || ConfMan.getBool("native_mt32"));
    132         //bool adlib = (midiDriver == MD_ADLIB);
     130        MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
     131        bool native_mt32 = ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32"));
     132        //bool adlib = (MidiDriver::getMusicType(dev) == MT_ADLIB);
    133133
    134         _midiDriver = MidiDriver::createMidi(midiDriver);
     134        _midiDriver = MidiDriver::createMidi(dev);
    135135        if (native_mt32)
    136136                _midiDriver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
    137137
  • engines/gob/gob.cpp

     
    345345}
    346346
    347347bool GobEngine::initGameParts() {
    348         _noMusic = MidiDriver::parseMusicDriver(ConfMan.get("music_driver")) == MD_NULL;
    349 
     348        // just detect some devices some of which will be always there if the music is not disabled
     349        _noMusic = MidiDriver::detectDevice(MDT_PCSPK | MDT_MIDI | MDT_ADLIB) ? false : true;
    350350        _saveLoad = 0;
    351351
    352352        _global    = new Global(this);
  • engines/groovie/music.cpp

     
    386386        _midiParser = MidiParser::createParser_XMIDI();
    387387
    388388        // Create the driver
    389         MidiDriverType driver = detectMusicDriver(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
    390         _driver = createMidi(driver);
     389        MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
     390        _driver = createMidi(dev);
    391391        this->open();
    392392
    393393        // Set the parser's driver
     
    402402        }
    403403
    404404        // Load the Global Timbre Library
    405         if (driver == MD_ADLIB) {
     405        if (MidiDriver::getMusicType(dev) == MT_ADLIB) {
    406406                // MIDI through AdLib
    407                 _musicType = MD_ADLIB;
     407                _musicType = MT_ADLIB;
    408408                loadTimbres(gtlName + ".ad");
    409409
    410410                // Setup the percussion channel
     
    412412                        if (_timbres[i].bank == 0x7F)
    413413                                setTimbreAD(9, _timbres[i]);
    414414                }
    415         } else if ((driver == MD_MT32) || ConfMan.getBool("native_mt32")) {
     415        } else if ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32")) {
    416416                // MT-32
    417                 _musicType = MD_MT32;
     417                _musicType = MT_MT32;
    418418                loadTimbres(gtlName + ".mt");
    419419        } else {
    420420                // GM
     
    455455                        for (int i = 0; i < numTimbres; i++) {
    456456                                if ((_timbres[i].bank == _chanBanks[chan]) &&
    457457                                        (_timbres[i].patch == patch)) {
    458                                         if (_musicType == MD_ADLIB) {
     458                                        if (_musicType == MT_ADLIB) {
    459459                                                setTimbreAD(chan, _timbres[i]);
    460                                         } else if (_musicType == MD_MT32) {
     460                                        } else if (_musicType == MT_MT32) {
    461461                                                setTimbreMT(chan, _timbres[i]);
    462462                                        }
    463463                                        return;
     
    682682        _midiParser = MidiParser::createParser_SMF();
    683683
    684684        // Create the driver
    685         MidiDriverType driver = detectMusicDriver(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
    686         _driver = createMidi(driver);
     685        MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
     686        _driver = createMidi(dev);
    687687        this->open();
    688688
    689689        // Set the parser's driver
  • engines/groovie/script.cpp

     
    8686        }
    8787
    8888        // Initialize the music type variable
    89         int midiDriver = MidiDriver::detectMusicDriver(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
    90         if (midiDriver == MD_ADLIB) {
     89        MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
     90        if (MidiDriver::getMusicType(dev) == MT_ADLIB) {
    9191                // MIDI through AdLib
    9292                setVariable(0x100, 0);
    93         } else if ((midiDriver == MD_MT32) || ConfMan.getBool("native_mt32")) {
     93        } else if ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32")) {
    9494                // MT-32
    9595                setVariable(0x100, 2);
    9696        } else {
  • engines/kyra/kyra_v1.cpp

     
    106106
    107107        if (!_flags.useDigSound) {
    108108                // We prefer AdLib over MIDI, since generally AdLib is better supported
    109                 MidiDriverType midiDriver = MidiDriver::detectMusicDriver(MDT_PCSPK | MDT_MIDI | MDT_ADLIB);
     109                MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_PCSPK | MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI | MDT_PREFER_MT32);
    110110
    111111                if (_flags.platform == Common::kPlatformFMTowns) {
    112112                        if (_flags.gameID == GI_KYRA1)
     
    120120                                _sound = new SoundTownsPC98_v2(this, _mixer);
    121121                } else if (_flags.platform == Common::kPlatformAmiga) {
    122122                        _sound = new SoundAmiga(this, _mixer);
    123                 } else if (midiDriver == MD_ADLIB) {
     123                } else if (MidiDriver::getMusicType(dev) == MT_ADLIB) {
    124124                        _sound = new SoundAdLibPC(this, _mixer);
    125125                } else {
    126126                        Sound::kType type;
    127127
    128                         if (midiDriver == MD_PCSPK)
     128                        if (MidiDriver::getMusicType(dev) == MT_PCSPK)
    129129                                type = Sound::kPCSpkr;
    130                         else if (midiDriver == MD_MT32 || ConfMan.getBool("native_mt32"))
     130                        else if (MidiDriver::getMusicType(dev) == MT_MT32 || ConfMan.getBool("native_mt32"))
    131131                                type = Sound::kMidiMT32;
    132132                        else
    133133                                type = Sound::kMidiGM;
    134134
    135135                        MidiDriver *driver = 0;
    136136
    137                         if (midiDriver == MD_PCSPK) {
     137                        if (MidiDriver::getMusicType(dev) == MT_PCSPK) {
    138138                                driver = new MidiDriver_PCSpeaker(_mixer);
    139139                        } else {
    140                                 driver = MidiDriver::createMidi(midiDriver);
     140                                driver = MidiDriver::createMidi(dev);
    141141                                if (type == Sound::kMidiMT32)
    142142                                        driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
    143143                        }
  • engines/lure/sound.cpp

     
    5050        _soundData = NULL;
    5151        _paused = false;
    5252
    53         MidiDriverType midiDriver = MidiDriver::detectMusicDriver(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
    54         _isRoland = midiDriver != MD_ADLIB;
    55         _nativeMT32 = ((midiDriver == MD_MT32) || ConfMan.getBool("native_mt32"));
     53        MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
     54        _isRoland = MidiDriver::getMusicType(dev) != MT_ADLIB;
     55        _nativeMT32 = ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32"));
    5656
    5757        Common::set_to(_channelsInUse, _channelsInUse + NUM_CHANNELS, false);
    5858
    59         _driver = MidiDriver::createMidi(midiDriver);
     59        _driver = MidiDriver::createMidi(dev);
    6060        int statusCode = _driver->open();
    6161        if (statusCode) {
    6262                warning("Sound driver returned error code %d", statusCode);
  • engines/m4/m4.cpp

     
    156156        // Initialize backend
    157157        _screen = new M4Surface(true); // Special form for creating screen reference
    158158
    159         MidiDriverType midiDriver = MidiDriver::detectMusicDriver(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
    160         bool native_mt32 = ((midiDriver == MD_MT32) || ConfMan.getBool("native_mt32"));
     159        MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
     160        bool native_mt32 = ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32"));
    161161
    162         _driver = MidiDriver::createMidi(midiDriver);
     162        _driver = MidiDriver::createMidi(dev);
    163163        if (native_mt32)
    164164                _driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
    165165
  • engines/made/made.cpp

     
    9797
    9898        _script = new ScriptInterpreter(this);
    9999
    100         MidiDriverType midiDriver = MidiDriver::detectMusicDriver(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
    101         bool native_mt32 = ((midiDriver == MD_MT32) || ConfMan.getBool("native_mt32"));
    102         //bool adlib = (midiDriver == MD_ADLIB);
     100        MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
     101        bool native_mt32 = ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32"));
     102        //bool adlib = (MidiDriver::getMusicType(dev) == MT_ADLIB);
    103103
    104         MidiDriver *driver = MidiDriver::createMidi(midiDriver);
     104        MidiDriver *driver = MidiDriver::createMidi(dev);
    105105        if (native_mt32)
    106106                driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
    107107
  • engines/mohawk/sound.cpp

     
    2727
    2828#include "common/util.h"
    2929
     30#include "sound/musicplugin.h"
    3031#include "sound/audiostream.h"
    3132#include "sound/decoders/mp3.h"
    3233#include "sound/decoders/raw.h"
    3334#include "sound/decoders/wave.h"
    3435
    35 
    3636namespace Mohawk {
    3737
    3838Sound::Sound(MohawkEngine* vm) : _vm(vm) {
     
    7979
    8080        // Let's get our MIDI parser/driver
    8181        _midiParser = MidiParser::createParser_SMF();
    82         _midiDriver = MidiDriver::createMidi(MidiDriver::detectMusicDriver(MDT_ADLIB|MDT_MIDI));
     82        _midiDriver = MidiDriver::createMidi(MidiDriver::detectDevice(MDT_ADLIB|MDT_MIDI));
    8383
    8484        // Set up everything!
    8585        _midiDriver->open();
  • engines/parallaction/parallaction_br.cpp

     
    6161                        _disk = new DosDisk_br(this);
    6262                }
    6363                _disk->setLanguage(2);                                  // NOTE: language is now hardcoded to English. Original used command-line parameters.
    64                 MidiDriverType midiDriver = MidiDriver::detectMusicDriver(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
    65                 MidiDriver *driver = MidiDriver::createMidi(midiDriver);
     64                MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
     65                MidiDriver *driver = MidiDriver::createMidi(dev);
    6666                _soundManI = new DosSoundMan_br(this, driver);
    6767        } else {
    6868                _disk = new AmigaDisk_br(this);
  • engines/parallaction/parallaction_ns.cpp

     
    2424 */
    2525
    2626#include "common/system.h"
    27 
    2827#include "common/config-manager.h"
    2928
    3029#include "parallaction/parallaction.h"
     
    167166        _disk->init();
    168167
    169168        if (getPlatform() == Common::kPlatformPC) {
    170                 MidiDriverType midiDriver = MidiDriver::detectMusicDriver(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
    171                 MidiDriver *driver = MidiDriver::createMidi(midiDriver);
     169                MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
     170                MidiDriver *driver = MidiDriver::createMidi(dev);
    172171                _soundManI = new DosSoundMan_ns(this, driver);
    173172                _soundManI->setMusicVolume(ConfMan.getInt("music_volume"));
    174173        } else {
  • engines/queen/music.cpp

     
    3434
    3535#include "sound/midiparser.h"
    3636
     37
    3738namespace Queen {
    3839
    3940extern MidiDriver *C_Player_CreateAdLibMidiDriver(Audio::Mixer *);
     
    4546        _queuePos = _lastSong = _currentSong = 0;
    4647        queueClear();
    4748
    48         MidiDriverType midiDriver = MidiDriver::detectMusicDriver(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
    49         _adlib = (midiDriver == MD_ADLIB);
    50         _nativeMT32 = ((midiDriver == MD_MT32) || ConfMan.getBool("native_mt32"));
     49        MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI | MDT_PREFER_MT32);
     50        _adlib = (MidiDriver::getMusicType(dev) == MT_ADLIB);
     51        _nativeMT32 = ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32"));
    5152
    5253        const char *musicDataFile;
    5354        if (vm->resource()->isDemo()) {
     
    7273//              }
    7374                _driver = C_Player_CreateAdLibMidiDriver(vm->_mixer);
    7475        } else {
    75                 _driver = MidiDriver::createMidi(midiDriver);
     76                _driver = MidiDriver::createMidi(dev);
    7677                if (_nativeMT32) {
    7778                        _driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
    7879                }
  • engines/saga/music.cpp

     
    4747        _masterVolume = 0;
    4848        _nativeMT32 = ConfMan.getBool("native_mt32");
    4949
    50         _driverType = MidiDriver::detectMusicDriver(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
    51         _driver = MidiDriver::createMidi(_driverType);
     50        MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
     51        _driver = MidiDriver::createMidi(dev);
    5252        if (isMT32())
    5353                _driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
    5454
  • engines/saga/music.h

     
    5252        void setVolume(int volume);
    5353        int getVolume() { return _masterVolume; }
    5454
    55         bool isAdlib() { return _driverType == MD_ADLIB; }
    56         bool isMT32() { return _driverType == MD_MT32 || _nativeMT32; }
     55        bool isAdlib() { return _driverType == MT_ADLIB; }
     56        bool isMT32() { return _driverType == MT_MT32 || _nativeMT32; }
    5757        void setGM(bool isGM) { _isGM = isGM; }
    5858
    5959        //MidiDriver interface implementation
     
    7878
    7979        MidiChannel *_channel[16];
    8080        MidiDriver *_driver;
    81         MidiDriverType _driverType;
     81        MusicType _driverType;
    8282        byte _channelVolume[16];
    8383        bool _isGM;
    8484        bool _nativeMT32;
  • engines/sci/sound/drivers/fb01.cpp

     
    128128};
    129129
    130130MidiPlayer_Fb01::MidiPlayer_Fb01(SciVersion version) : MidiPlayer(version), _playSwitch(true), _masterVolume(15), _timerParam(NULL), _timerProc(NULL) {
    131         MidiDriverType midiType = MidiDriver::detectMusicDriver(MDT_MIDI);
    132         _driver = createMidi(midiType);
     131        MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI);
     132        _driver = createMidi(dev);
    133133
    134134        _sysExBuf[0] = 0x43;
    135135        _sysExBuf[1] = 0x75;
  • engines/sci/sound/drivers/midi.cpp

     
    119119};
    120120
    121121MidiPlayer_Midi::MidiPlayer_Midi(SciVersion version) : MidiPlayer(version), _playSwitch(true), _masterVolume(15), _isMt32(false), _hasReverb(false), _isOldPatchFormat(true) {
    122         MidiDriverType midiType = MidiDriver::detectMusicDriver(MDT_MIDI);
    123         _driver = createMidi(midiType);
     122        MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI);
     123        _driver = createMidi(dev);
    124124
    125         if (midiType == MD_MT32 || ConfMan.getBool("native_mt32"))
     125        if (MidiDriver::getMusicType(dev) == MT_MT32 || ConfMan.getBool("native_mt32"))
    126126                _isMt32 = true;
    127127
    128128        _sysExBuf[0] = 0x41;
  • engines/sci/sound/iterator/core.cpp

     
    223223/* API implementation */
    224224
    225225Common::Error SfxPlayer::init(ResourceManager *resMan, int expected_latency) {
    226         MidiDriverType musicDriver = MidiDriver::detectMusicDriver(MDT_PCSPK | MDT_ADLIB);
     226        MidiDriverType musicDriver = MidiDriver::detectDevice(MDT_PCSPK | MDT_ADLIB);
    227227
    228228        switch (musicDriver) {
    229229        case MD_ADLIB:
  • engines/sci/sound/music.cpp

     
    6161        // SCI sound init
    6262        _dwTempo = 0;
    6363
    64         MidiDriverType midiType;
    65 
    6664        // Default to MIDI in SCI32 games, as many don't have AdLib support.
    6765        // WORKAROUND: Default to MIDI in Amiga SCI1_EGA+ games as we don't support those patches yet.
    6866        // We also don't yet support the 7.pat file of SCI1+ Mac games or SCI0 Mac patches, so we
    6967        // default to MIDI in those games to let them run.
    7068        Common::Platform platform = g_sci->getPlatform();
     69        uint32 dev =  MidiDriver::detectDevice((getSciVersion() >= SCI_VERSION_2 || platform == Common::kPlatformMacintosh || (platform == Common::kPlatformAmiga && getSciVersion() >= SCI_VERSION_1_EGA)) ? (MDT_PCSPK | MDT_ADLIB | MDT_MIDI | MDT_PREFER_MIDI) : (MDT_PCSPK | MDT_ADLIB | MDT_MIDI));
    7170
    72         if (getSciVersion() >= SCI_VERSION_2 || platform == Common::kPlatformMacintosh || (platform == Common::kPlatformAmiga && getSciVersion() >= SCI_VERSION_1_EGA))
    73                 midiType = MidiDriver::detectMusicDriver(MDT_PCSPK | MDT_ADLIB | MDT_MIDI | MDT_PREFER_MIDI);
    74         else
    75                 midiType = MidiDriver::detectMusicDriver(MDT_PCSPK | MDT_ADLIB | MDT_MIDI);
    76 
    77         switch (midiType) {
    78         case MD_ADLIB:
     71        switch (MidiDriver::getMusicType(dev)) {
     72        case MT_ADLIB:
    7973                // FIXME: There's no Amiga sound option, so we hook it up to AdLib
    8074                if (g_sci->getPlatform() == Common::kPlatformAmiga)
    8175                        _pMidiDrv = MidiPlayer_Amiga_create(_soundVersion);
    8276                else
    8377                        _pMidiDrv = MidiPlayer_AdLib_create(_soundVersion);
    8478                break;
    85         case MD_PCJR:
     79        case MT_PCJR:
    8680                _pMidiDrv = MidiPlayer_PCJr_create(_soundVersion);
    8781                break;
    88         case MD_PCSPK:
     82        case MT_PCSPK:
    8983                _pMidiDrv = MidiPlayer_PCSpeaker_create(_soundVersion);
    9084                break;
    9185        default:
  • engines/scumm/detection.cpp

     
    896896                        }
    897897                }
    898898
    899                 dg.setGUIOptions(x->game.guioptions | MidiDriver::midiDriverFlags2GUIO(x->game.midi));
     899                dg.setGUIOptions(x->game.guioptions | MidiDriver::musicType2GUIO(x->game.midi));
    900900                dg.appendGUIOptions(getGameGUIOptionsDescriptionLanguage(x->language));
    901901
    902902                detectedGames.push_back(dg);
  • engines/scumm/detection_tables.h

     
    224224        {"indy3", "VGA",      "vga", GID_INDY3, 3, 0, MDT_PCSPK | MDT_ADLIB, GF_OLD256 | GF_FEW_LOCALS,                  Common::kPlatformPC, GUIO_NOSPEECH | GUIO_NOMIDI},
    225225        {"indy3", "FM-TOWNS",     0, GID_INDY3, 3, 0, MDT_TOWNS,             GF_OLD256 | GF_FEW_LOCALS | GF_AUDIOTRACKS, Common::kPlatformFMTowns, GUIO_NOSPEECH | GUIO_NOMIDI},
    226226
    227         {"loom", "EGA",      "ega", GID_LOOM, 3, 0, MDT_PCSPK | MDT_CMS | MDT_ADLIB | MDT_MIDI, 0, UNK, GUIO_NOSPEECH},
     227        {"loom", "EGA",      "ega", GID_LOOM, 3, 0, MDT_PCSPK | MDT_CMS | MDT_ADLIB | MDT_MIDI | MDT_PREFER_MIDI | MDT_PREFER_MT32, 0, UNK, GUIO_NOSPEECH},
    228228        {"loom", "No AdLib", "ega", GID_LOOM, 3, 0, MDT_PCSPK | MDT_CMS,                        0, UNK, GUIO_NOSPEECH | GUIO_NOMIDI},
    229229#ifdef USE_RGB_COLOR
    230230        {"loom", "PC-Engine",    0, GID_LOOM, 3, 0, MDT_NONE,                         GF_AUDIOTRACKS | GF_OLD256 | GF_16BIT_COLOR, Common::kPlatformPCEngine, GUIO_NOSPEECH | GUIO_NOMIDI},
     
    234234
    235235        {"pass", 0, 0, GID_PASS, 4, 0, MDT_PCSPK | MDT_ADLIB, GF_16COLOR, Common::kPlatformPC, GUIO_NOSPEECH | GUIO_NOMIDI},
    236236
    237         {"monkey", "VGA",      "vga", GID_MONKEY_VGA, 4, 0, MDT_PCSPK | MDT_ADLIB | MDT_MIDI, 0, UNK, GUIO_NOSPEECH},
    238         {"monkey", "EGA",      "ega", GID_MONKEY_EGA, 4, 0, MDT_PCSPK | MDT_CMS | MDT_ADLIB | MDT_MIDI, GF_16COLOR,     Common::kPlatformPC, GUIO_NOSPEECH},
     237        {"monkey", "VGA",      "vga", GID_MONKEY_VGA, 4, 0, MDT_PCSPK | MDT_ADLIB | MDT_MIDI | MDT_PREFER_MIDI | MDT_PREFER_MT32, 0, UNK, GUIO_NOSPEECH},
     238        {"monkey", "EGA",      "ega", GID_MONKEY_EGA, 4, 0, MDT_PCSPK | MDT_CMS | MDT_ADLIB | MDT_MIDI | MDT_PREFER_MIDI | MDT_PREFER_MT32, GF_16COLOR,     Common::kPlatformPC, GUIO_NOSPEECH},
    239239        {"monkey", "No AdLib", "ega", GID_MONKEY_EGA, 4, 0, MDT_PCSPK,                        GF_16COLOR,     Common::kPlatformAtariST, GUIO_NOSPEECH | GUIO_NOMIDI},
    240240        {"monkey", "Demo",     "ega", GID_MONKEY_EGA, 4, 0, MDT_PCSPK | MDT_ADLIB,            GF_16COLOR,     Common::kPlatformPC, GUIO_NOSPEECH | GUIO_NOMIDI},
    241241        {"monkey", "CD",           0, GID_MONKEY,     5, 0, MDT_ADLIB,                        GF_AUDIOTRACKS, UNK, GUIO_NOSPEECH | GUIO_NOMIDI},
    242242        {"monkey", "FM-TOWNS",     0, GID_MONKEY,     5, 0, MDT_ADLIB,                        GF_AUDIOTRACKS, Common::kPlatformFMTowns, GUIO_NOSPEECH | GUIO_NOMIDI},
    243243        {"monkey", "SEGA",         0, GID_MONKEY,     5, 0, MDT_NONE,                         GF_AUDIOTRACKS, Common::kPlatformSegaCD, GUIO_NOSPEECH | GUIO_NOMIDI},
    244244
    245         {"monkey2",  0, 0, GID_MONKEY2,  5, 0, MDT_ADLIB | MDT_MIDI, 0, UNK, GUIO_NOSPEECH},
     245        {"monkey2",  0, 0, GID_MONKEY2,  5, 0, MDT_ADLIB | MDT_MIDI | MDT_PREFER_MIDI | MDT_PREFER_MT32, 0, UNK, GUIO_NOSPEECH},
    246246
    247         {"atlantis", "" , 0, GID_INDY4,    5, 0, MDT_ADLIB | MDT_MIDI, 0, UNK, GUIO_NONE},
    248         {"atlantis", "Floppy", 0, GID_INDY4,    5, 0, MDT_ADLIB | MDT_MIDI, 0, UNK, GUIO_NOSPEECH},
     247        {"atlantis", "" , 0, GID_INDY4,    5, 0, MDT_ADLIB | MDT_MIDI | MDT_PREFER_MIDI | MDT_PREFER_MT32, 0, UNK, GUIO_NONE},
     248        {"atlantis", "Floppy", 0, GID_INDY4,    5, 0, MDT_ADLIB | MDT_MIDI | MDT_PREFER_MIDI | MDT_PREFER_MT32, 0, UNK, GUIO_NOSPEECH},
    249249
    250         {"tentacle", "", 0, GID_TENTACLE, 6, 0, MDT_ADLIB | MDT_MIDI, GF_USE_KEY, UNK, GUIO_NONE},
    251         {"tentacle", "Floppy", 0, GID_TENTACLE, 6, 0, MDT_ADLIB | MDT_MIDI, GF_USE_KEY, UNK, GUIO_NOSPEECH},
     250        {"tentacle", "", 0, GID_TENTACLE, 6, 0, MDT_ADLIB | MDT_MIDI | MDT_PREFER_MIDI | MDT_PREFER_GM, GF_USE_KEY, UNK, GUIO_NONE},
     251        {"tentacle", "Floppy", 0, GID_TENTACLE, 6, 0, MDT_ADLIB | MDT_MIDI | MDT_PREFER_MIDI | MDT_PREFER_GM, GF_USE_KEY, UNK, GUIO_NOSPEECH},
    252252
    253         {"samnmax",  "", 0, GID_SAMNMAX,  6, 0, MDT_ADLIB | MDT_MIDI, GF_USE_KEY, UNK, GUIO_NONE},
    254         {"samnmax",  "Floppy", 0, GID_SAMNMAX,  6, 0, MDT_ADLIB | MDT_MIDI, GF_USE_KEY, UNK, GUIO_NOSPEECH},
     253        {"samnmax",  "", 0, GID_SAMNMAX,  6, 0, MDT_ADLIB | MDT_MIDI | MDT_PREFER_MIDI | MDT_PREFER_GM, GF_USE_KEY, UNK, GUIO_NONE},
     254        {"samnmax",  "Floppy", 0, GID_SAMNMAX,  6, 0, MDT_ADLIB | MDT_MIDI | MDT_PREFER_MIDI | MDT_PREFER_GM, GF_USE_KEY, UNK, GUIO_NOSPEECH},
    255255
    256256#ifdef ENABLE_SCUMM_7_8
    257257        {"ft",       0, 0, GID_FT,  7, 0, MDT_NONE, 0, UNK, GUIO_NOMIDI},
  • engines/scumm/scumm.cpp

     
    16341634#endif
    16351635
    16361636void ScummEngine::setupMusic(int midi) {
    1637         MidiDriverType midiDriver = MidiDriver::detectMusicDriver(midi);
    1638         _native_mt32 = ((midiDriver == MD_MT32) || ConfMan.getBool("native_mt32"));
     1637        MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(midi);
     1638        _native_mt32 = ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32"));
    16391639
    1640         switch (midiDriver) {
    1641         case MD_NULL:
     1640        switch (MidiDriver::getMusicType(dev)) {
     1641        case MT_NULL:
    16421642                _musicType = MDT_NONE;
    16431643                break;
    1644         case MD_PCSPK:
    1645         case MD_PCJR:
     1644        case MT_PCSPK:
     1645        case MT_PCJR:
    16461646                _musicType = MDT_PCSPK;
    16471647                break;
    1648         case MD_CMS:
     1648        //case MT_CMS:
    16491649#if 1
    16501650                _musicType = MDT_ADLIB;
    16511651#else
    16521652                _musicType = MDT_CMS; // Still has number of bugs, disable by default
    16531653#endif
    16541654                break;
    1655         case MD_TOWNS:
     1655        case MT_TOWNS:
    16561656                _musicType = MDT_TOWNS;
    16571657                break;
    1658         case MD_ADLIB:
     1658        case MT_ADLIB:
    16591659                _musicType = MDT_ADLIB;
    16601660                break;
    16611661        default:
     
    17071707        if (!_mixer->isReady()) {
    17081708                warning("Sound mixer initialization failed");
    17091709                if (_musicType == MDT_ADLIB || _musicType == MDT_PCSPK || _musicType == MDT_CMS)        {
    1710                         midiDriver = MD_NULL;
     1710                        dev = 0;
    17111711                        _musicType = MDT_NONE;
    17121712                        warning("MIDI driver depends on sound mixer, switching to null MIDI driver");
    17131713                }
     
    17351735        } else if (_game.platform == Common::kPlatformAmiga && _game.version <= 4) {
    17361736                _musicEngine = new Player_V4A(this, _mixer);
    17371737        } else if (_game.id == GID_MANIAC && _game.version == 1) {
    1738                 _musicEngine = new Player_V1(this, _mixer, midiDriver != MD_PCSPK);
     1738                _musicEngine = new Player_V1(this, _mixer, MidiDriver::getMusicType(dev) != MT_PCSPK);
    17391739        } else if (_game.version <= 2) {
    1740                 _musicEngine = new Player_V2(this, _mixer, midiDriver != MD_PCSPK);
     1740                _musicEngine = new Player_V2(this, _mixer, MidiDriver::getMusicType(dev) != MT_PCSPK);
    17411741        } else if ((_musicType == MDT_PCSPK) && (_game.version > 2 && _game.version <= 4)) {
    1742                 _musicEngine = new Player_V2(this, _mixer, midiDriver != MD_PCSPK);
     1742                _musicEngine = new Player_V2(this, _mixer, MidiDriver::getMusicType(dev) != MT_PCSPK);
    17431743        } else if (_musicType == MDT_CMS) {
    17441744                _musicEngine = new Player_V2CMS(this, _mixer);
    17451745        } else if (_game.platform == Common::kPlatform3DO && _game.heversion <= 62) {
     
    17491749                MidiDriver *adlibMidiDriver = 0;
    17501750
    17511751                if (_musicType != MDT_ADLIB)
    1752                         nativeMidiDriver = MidiDriver::createMidi(midiDriver);
     1752                        nativeMidiDriver = MidiDriver::createMidi(dev);
    17531753                if (nativeMidiDriver != NULL && _native_mt32)
    17541754                        nativeMidiDriver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
    17551755                bool multi_midi = ConfMan.getBool("multi_midi") && _musicType != MDT_NONE && (midi & MDT_ADLIB);
    17561756                if (_musicType == MDT_ADLIB || multi_midi) {
    1757                         adlibMidiDriver = MidiDriver_ADLIB_create();
     1757                        adlibMidiDriver = MidiDriver::createMidi(MidiDriver::detectDevice(MDT_ADLIB));
    17581758                        adlibMidiDriver->property(MidiDriver::PROP_OLD_ADLIB, (_game.features & GF_SMALL_HEADER) ? 1 : 0);
    17591759                }
    17601760
     
    17691769                        // YM2162 driver can't handle midi->getPercussionChannel(), NULL shouldn't init MT-32/GM/GS
    17701770                        if ((midi != MDT_TOWNS) && (midi != MDT_NONE)) {
    17711771                                _imuse->property(IMuse::PROP_NATIVE_MT32, _native_mt32);
    1772                                 if (midiDriver != MD_MT32) // MT-32 Emulation shouldn't be GM/GS initialized
     1772                                if (MidiDriver::getMusicType(dev) != MT_MT32) // MT-32 Emulation shouldn't be GM/GS initialized
    17731773                                        _imuse->property(IMuse::PROP_GS, _enable_gs);
    17741774                        }
    17751775                        if (_game.heversion >= 60 || midi == MDT_TOWNS) {
  • engines/sky/sky.cpp

     
    259259
    260260        _systemVars.gameVersion = _skyDisk->determineGameVersion();
    261261
    262         MidiDriverType midiDriver = MidiDriver::detectMusicDriver(MDT_ADLIB | MDT_MIDI | MDT_PREFER_MIDI);
    263         if (midiDriver == MD_ADLIB) {
     262        MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_ADLIB | MDT_MIDI | MDT_PREFER_MIDI | MDT_PREFER_MT32);
     263        if (MidiDriver::getMusicType(dev) == MT_ADLIB) {
    264264                _systemVars.systemFlags |= SF_SBLASTER;
    265265                _skyMusic = new AdLibMusic(_mixer, _skyDisk);
    266266        } else {
    267267                _systemVars.systemFlags |= SF_ROLAND;
    268                 if ((midiDriver == MD_MT32) || ConfMan.getBool("native_mt32"))
    269                         _skyMusic = new MT32Music(MidiDriver::createMidi(midiDriver), _skyDisk);
     268                if ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32"))
     269                        _skyMusic = new MT32Music(MidiDriver::createMidi(dev), _skyDisk);
    270270                else
    271                         _skyMusic = new GmMusic(MidiDriver::createMidi(midiDriver), _skyDisk);
     271                        _skyMusic = new GmMusic(MidiDriver::createMidi(dev), _skyDisk);
    272272        }
    273273
    274274        if (isCDVersion()) {
  • engines/tinsel/tinsel.cpp

     
    856856        if (cd_num >= 0)
    857857                _system->openCD(cd_num);
    858858
    859         MidiDriverType midiDriver = MidiDriver::detectMusicDriver(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
    860         bool native_mt32 = ((midiDriver == MD_MT32) || ConfMan.getBool("native_mt32"));
    861         //bool adlib = (midiDriver == MD_ADLIB);
     859        MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
     860        bool native_mt32 = ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32"));
     861        //bool adlib = (MidiDriver::getMusicType(dev) == MT_ADLIB);
    862862
    863         _driver = MidiDriver::createMidi(midiDriver);
     863        _driver = MidiDriver::createMidi(dev);
    864864        if (native_mt32)
    865865                _driver->property(MidiDriver::PROP_CHANNEL_MASK, 0x03FE);
    866866
  • engines/touche/midi.cpp

     
    9292}
    9393
    9494int MidiPlayer::open() {
    95         MidiDriverType midiDriver = MidiDriver::detectMusicDriver(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
    96         _nativeMT32 = ((midiDriver == MD_MT32) || ConfMan.getBool("native_mt32"));
    97         _driver = MidiDriver::createMidi(midiDriver);
     95        MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI | MDT_ADLIB | MDT_PREFER_MIDI);
     96        _nativeMT32 = ((MidiDriver::getMusicType(dev) == MT_MT32) || ConfMan.getBool("native_mt32"));
     97        _driver = MidiDriver::createMidi(dev);
    9898        int ret = _driver->open();
    9999        if (ret == 0) {
    100100                _parser = MidiParser::createParser_SMF();
  • gui/options.cpp

     
    4040#include "graphics/scaler.h"
    4141
    4242#include "sound/mididrv.h"
     43#include "sound/musicplugin.h"
    4344#include "sound/mixer.h"
    4445#include "sound/fmopl.h"
    4546
     
    99100        _aspectCheckbox = 0;
    100101        _enableAudioSettings = false;
    101102        _midiPopUp = 0;
     103        _mt32DevicePopUp = 0;
     104        _gmDevicePopUp = 0;
    102105        _oplPopUp = 0;
    103106        _outputRatePopUp = 0;
    104107        _enableMIDISettings = false;
     
    133136        }
    134137}
    135138
     139template<class T> bool prdEqualsDeviceProperty(MusicDevices::iterator d, T lookupProp, Common::MemFunc0<T, MusicDevice> devicePropFunc) {
     140        return lookupProp == devicePropFunc(&*d);
     141}
     142
     143bool prdMidiDefault(MusicDevices::iterator d, Common::String dom, bool, MusicPlugin::List::const_iterator&) {
     144        return !(dom == Common::ConfigManager::kApplicationDomain && d->getMusicType() == MT_TOWNS) ? true : false;
     145}
     146
     147bool prdMidiSpec(MusicDevices::iterator d, Common::String, bool isAutoPlugin, MusicPlugin::List::const_iterator &m) {
     148        if (isAutoPlugin)
     149                m++;
     150        return ((d->getMusicType() >= MT_GM) || isAutoPlugin) ? true : false;
     151}
     152
    136153void OptionsDialog::open() {
    137154        Dialog::open();
    138155
     
    191208        }
    192209
    193210        // Audio options
    194         if (_midiPopUp) {
    195                 // Music driver
    196                 MidiDriverType id = MidiDriver::parseMusicDriver(ConfMan.get("music_driver", _domain));
    197                 _midiPopUp->setSelectedTag(id);
     211        if (!loadMusicDeviceSetting(_midiPopUp, "music_driver", prdMidiDefault))
     212                _midiPopUp->setSelected(0);
     213
     214        if (!loadMusicDeviceSetting(_mt32DevicePopUp, "mt32_device", prdMidiSpec)) {
     215                if (_domain.equals(Common::ConfigManager::kApplicationDomain)) {
     216                        if (!loadMusicDeviceSetting(_mt32DevicePopUp, "", prdMidiSpec, MT_MT32))
     217                                _mt32DevicePopUp->setSelected(0);
     218                } else {
     219                        _mt32DevicePopUp->setSelected(0);
     220                }
    198221        }
    199222
     223        if (!loadMusicDeviceSetting(_gmDevicePopUp, "gm_device", prdMidiSpec)) {
     224                if (_domain.equals(Common::ConfigManager::kApplicationDomain)) {
     225                        if (!loadMusicDeviceSetting(_gmDevicePopUp, "", prdMidiSpec, MT_GM))
     226                                _gmDevicePopUp->setSelected(0);
     227                } else {
     228                        _gmDevicePopUp->setSelected(0);
     229                }
     230        }
     231
    200232        if (_oplPopUp) {
    201233                OPL::Config::DriverId id = MAX<OPL::Config::DriverId>(OPL::Config::parse(ConfMan.get("opl_driver", _domain)), 0);
    202234                _oplPopUp->setSelectedTag(id);
     
    332364                }
    333365
    334366                // Audio options
    335                 if (_midiPopUp) {
    336                         if (_enableAudioSettings) {
    337                                 const MidiDriverDescription *md = MidiDriver::getAvailableMidiDrivers();
    338                                 while (md->name && md->id != (int)_midiPopUp->getSelectedTag())
    339                                         md++;
    340                                 if (md->name)
    341                                         ConfMan.set("music_driver", md->name, _domain);
    342                                 else
    343                                         ConfMan.removeKey("music_driver", _domain);
    344                         } else {
    345                                 ConfMan.removeKey("music_driver", _domain);
    346                         }
    347                 }
     367                saveMusicDeviceSetting(_midiPopUp, "music_driver", prdMidiDefault);
     368                saveMusicDeviceSetting(_mt32DevicePopUp, "mt32_device", prdMidiSpec);
     369                saveMusicDeviceSetting(_gmDevicePopUp, "gm_device", prdMidiSpec);
    348370
    349371                if (_oplPopUp) {
    350372                        if (_enableAudioSettings) {
     
    495517
    496518void OptionsDialog::setAudioSettingsState(bool enabled) {
    497519        _enableAudioSettings = enabled;
    498 
    499520        _midiPopUpDesc->setEnabled(enabled);
    500521        _midiPopUp->setEnabled(enabled);
     522        _mt32DevicePopUpDesc->setEnabled(_domain.equals(Common::ConfigManager::kApplicationDomain) ? enabled : false);
     523        _mt32DevicePopUp->setEnabled(_domain.equals(Common::ConfigManager::kApplicationDomain) ? enabled : false);
     524        _gmDevicePopUpDesc->setEnabled(_domain.equals(Common::ConfigManager::kApplicationDomain) ? enabled : false);
     525        _gmDevicePopUp->setEnabled(_domain.equals(Common::ConfigManager::kApplicationDomain) ? enabled : false);
    501526
    502         uint32 allFlags = MidiDriver::midiDriverFlags2GUIO((uint32)-1);
     527        uint32 allFlags = MidiDriver::musicType2GUIO((uint32)-1);
    503528
    504529        if (_domain != Common::ConfigManager::kApplicationDomain && // global dialog
    505                                 (_guioptions & allFlags) && // No flags are specified
     530                        (_guioptions & allFlags) && // No flags are specified
    506531                                !(_guioptions & Common::GUIO_MIDIADLIB)) {
    507532                _oplPopUpDesc->setEnabled(false);
    508533                _oplPopUp->setEnabled(false);
     
    623648
    624649void OptionsDialog::addAudioControls(GuiObject *boss, const Common::String &prefix) {
    625650        // The MIDI mode popup & a label
    626         _midiPopUpDesc = new StaticTextWidget(boss, prefix + "auMidiPopupDesc", _("Music driver:"), _("Specifies output sound device or sound card emulator"));
     651        _midiPopUpDesc = new StaticTextWidget(boss, prefix + "auMidiPopupDesc", _(_domain == Common::ConfigManager::kApplicationDomain ? "Preferred Device:" : "Music Device:"), _(_domain == Common::ConfigManager::kApplicationDomain ? "Specifies preferred sound device or sound card emulator" : "Specifies output sound device or sound card emulator"));
    627652        _midiPopUp = new PopUpWidget(boss, prefix + "auMidiPopup", _("Specifies output sound device or sound card emulator"));
    628653
     654        _mt32DevicePopUpDesc = new StaticTextWidget(boss, prefix + "auPrefMt32PopupDesc", _("MT32 Device:"), _("Specifies default sound device for Roland MT-32/LAPC1/CM32l/CM64 output"));
     655        _mt32DevicePopUp = new PopUpWidget(boss, prefix + "auPrefMt32Popup");
     656        _gmDevicePopUpDesc = new StaticTextWidget(boss, prefix + "auPrefGmPopupDesc", _("GM Device:"), _("Specifies default sound device for General Midi output"));
     657        _gmDevicePopUp = new PopUpWidget(boss, prefix + "auPrefGmPopup");
     658
    629659        // Populate it
    630         const MidiDriverDescription *md = MidiDriver::getAvailableMidiDrivers();
    631         uint32 allFlags = MidiDriver::midiDriverFlags2GUIO((uint32)-1);
     660        uint32 allFlags = MidiDriver::musicType2GUIO((uint32)-1);
    632661
    633         while (md->name) {
    634                 if (_domain == Common::ConfigManager::kApplicationDomain || // global dialog
    635                                 !(_guioptions & allFlags) || // No flags are specified
    636                                 _guioptions & (MidiDriver::midiDriverFlags2GUIO(md->flags))) // flag is present
    637                         _midiPopUp->appendEntry(_(md->description), md->id);
    638                 md++;
     662        const MusicPlugin::List p = MusicMan.getPlugins();
     663        int musicId = 0;
     664        int midiId = 0;
     665        for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) {
     666                MusicDevices i = (**m)->getDevices();
     667                for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) {
     668                        if ((_domain == Common::ConfigManager::kApplicationDomain && d->getMusicType() != MT_TOWNS) || // global dialog - skip useless FM-Towns option there
     669                                (_domain != Common::ConfigManager::kApplicationDomain && !(_guioptions & allFlags)) || // No flags are specified
     670                                _guioptions & (MidiDriver::musicType2GUIO(d->getMusicType()))) // flag is present
     671                                        _midiPopUp->appendEntry(d->getCompleteName(), musicId++);
     672                        if (d->getMusicType() >= MT_GM || m == p.begin()) {
     673                                _mt32DevicePopUp->appendEntry(d->getCompleteName(), midiId);
     674                                _gmDevicePopUp->appendEntry(d->getCompleteName(), midiId++);
     675                        }
     676                }
    639677        }
    640678
     679        if (!_domain.equals(Common::ConfigManager::kApplicationDomain)) {
     680                _mt32DevicePopUpDesc->setEnabled(false);
     681                _mt32DevicePopUp->setEnabled(false);
     682                _gmDevicePopUpDesc->setEnabled(false);
     683                _gmDevicePopUp->setEnabled(false);
     684        }
     685
    641686        // The OPL emulator popup & a label
    642687        _oplPopUpDesc = new StaticTextWidget(boss, prefix + "auOPLPopupDesc", _("AdLib emulator:"), _("AdLib is used for music in many games"));
    643688        _oplPopUp = new PopUpWidget(boss, prefix + "auOPLPopup", _("AdLib is used for music in many games"));
     
    745790        _enableVolumeSettings = true;
    746791}
    747792
     793bool OptionsDialog::loadMusicDeviceSetting(PopUpWidget *popup, Common::String setting, MidiSettingsExtraPred pred, MusicType preferredType) {
     794        if (!popup || !popup->isEnabled())
     795                return true;
     796
     797        if (ConfMan.hasKey(setting, _domain) || preferredType) {
     798                const Common::String drv = ConfMan.get(setting, _domain);
     799                const MusicPlugin::List p = MusicMan.getPlugins();
     800                int id = 0;
     801                for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end() && id != -1; m++) {
     802                        MusicDevices i = (**m)->getDevices();
     803                        for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) {
     804                                if ((setting.empty() && preferredType) ? prdEqualsDeviceProperty(d, preferredType, Common::mem_fun(&MusicDevice::getMusicType)) : prdEqualsDeviceProperty(d, drv, Common::mem_fun(&MusicDevice::getCompleteId))) {
     805                                        popup->setSelected(id);
     806                                        id = -1;                                                                                               
     807                                        break;
     808                                } else if (pred(d, _domain, m == p.begin(), m)) {
     809                                        id++;
     810                                }
     811                        }
     812                }
     813                if (id != -1)
     814                        // midi device turned off or whatever
     815                        return false;           
     816        } else {
     817                return false;
     818        }
     819
     820        return true;
     821}
     822
     823void OptionsDialog::saveMusicDeviceSetting(PopUpWidget *popup, Common::String setting, MidiSettingsExtraPred pred) {
     824        if (!popup || !_enableAudioSettings)
     825                return;
     826       
     827        const MusicPlugin::List p = MusicMan.getPlugins();
     828        uint32 id = 0;
     829        bool found = false;
     830        for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end() && !found; m++) {
     831                MusicDevices i = (**m)->getDevices();
     832                for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) {
     833                        if (id == popup->getSelectedTag()) {
     834                                ConfMan.set(setting, d->getCompleteId(), _domain);
     835                                found = true;
     836                                break;
     837                        } else if (pred(d, _domain, m == p.begin(), m)) {
     838                                id++;
     839                        }
     840                }
     841        }
     842
     843        if (!found)
     844                ConfMan.removeKey(setting, _domain);
     845}
     846
    748847int OptionsDialog::getSubtitleMode(bool subtitles, bool speech_mute) {
    749848        if (_guioptions & Common::GUIO_NOSUBTITLES)
    750849                return kSubtitlesSpeech; // Speech only
  • gui/options.h

     
    2828#include "gui/dialog.h"
    2929#include "gui/TabWidget.h"
    3030#include "common/str.h"
     31#include "sound/musicplugin.h"
    3132
    3233#ifdef SMALL_SCREEN_DEVICE
    3334#include "gui/KeysDialog.h"
     
    7879        void setVolumeSettingsState(bool enabled);
    7980        void setSubtitleSettingsState(bool enabled);
    8081
     82        typedef bool (MidiSettingsExtraPred)(MusicDevices::iterator, Common::String, bool, MusicPlugin::List::const_iterator&);
     83        bool loadMusicDeviceSetting(PopUpWidget *popup, Common::String setting, MidiSettingsExtraPred pred, MusicType preferredType = MT_NULL);
     84        void saveMusicDeviceSetting(PopUpWidget *popup, Common::String setting, MidiSettingsExtraPred pred);
     85
    8186        TabWidget *_tabWidget;
    8287        int _graphicsTabId;
    8388
     
    104109        StaticTextWidget *_outputRatePopUpDesc;
    105110        PopUpWidget *_outputRatePopUp;
    106111
     112        StaticTextWidget *_mt32DevicePopUpDesc;
     113        PopUpWidget *_mt32DevicePopUp;
     114        StaticTextWidget *_gmDevicePopUpDesc;
     115        PopUpWidget *_gmDevicePopUp;
     116
     117
     118
    107119        //
    108120        // MIDI controls
    109121        //
  • gui/themes/default.inc

     
    615615"/> "
    616616"</layout> "
    617617"<layout type='horizontal' padding='0,0,0,0' spacing='10' center='true'> "
     618"<widget name='auPrefMt32PopupDesc' "
     619"type='OptionsLabel' "
     620"/> "
     621"<widget name='auPrefMt32Popup' "
     622"type='PopUp' "
     623"/> "
     624"</layout> "
     625"<layout type='horizontal' padding='0,0,0,0' spacing='10' center='true'> "
     626"<widget name='auPrefGmPopupDesc' "
     627"type='OptionsLabel' "
     628"/> "
     629"<widget name='auPrefGmPopup' "
     630"type='PopUp' "
     631"/> "
     632"</layout> "
     633"<layout type='horizontal' padding='0,0,0,0' spacing='10' center='true'> "
    618634"<widget name='auOPLPopupDesc' "
    619635"type='OptionsLabel' "
    620636"/> "
     
    13701386"/> "
    13711387"</layout> "
    13721388"<layout type='horizontal' padding='0,0,0,0' spacing='6' center='true'> "
     1389"<widget name='auPrefMt32PopupDesc' "
     1390"type='OptionsLabel' "
     1391"/> "
     1392"<widget name='auPrefMt32Popup' "
     1393"type='PopUp' "
     1394"/> "
     1395"</layout> "
     1396"<layout type='horizontal' padding='0,0,0,0' spacing='6' center='true'> "
     1397"<widget name='auPrefGmPopupDesc' "
     1398"type='OptionsLabel' "
     1399"/> "
     1400"<widget name='auPrefGmPopup' "
     1401"type='PopUp' "
     1402"/> "
     1403"</layout> "
     1404"<layout type='horizontal' padding='0,0,0,0' spacing='6' center='true'> "
    13731405"<widget name='auOPLPopupDesc' "
    13741406"type='OptionsLabel' "
    13751407"/> "
  • gui/themes/scummclassic/classic_layout.stx

     
    232232                                />
    233233                        </layout>
    234234                        <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10' center = 'true'>
     235                                <widget name = 'auPrefMt32PopupDesc'
     236                                                type = 'OptionsLabel'
     237                                />
     238                                <widget name = 'auPrefMt32Popup'
     239                                                type = 'PopUp'
     240                                />
     241                        </layout>
     242                        <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10' center = 'true'>
     243                                <widget name = 'auPrefGmPopupDesc'
     244                                                type = 'OptionsLabel'
     245                                />
     246                                <widget name = 'auPrefGmPopup'
     247                                                type = 'PopUp'
     248                                />
     249                        </layout>
     250                        <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10' center = 'true'>
    235251                                <widget name = 'auOPLPopupDesc'
    236252                                                type = 'OptionsLabel'
    237253                                />
  • gui/themes/scummclassic/classic_layout_lowres.stx

     
    230230                                />
    231231                        </layout>
    232232                        <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '6' center = 'true'>
     233                                <widget name = 'auPrefMt32PopupDesc'
     234                                                type = 'OptionsLabel'
     235                                />
     236                                <widget name = 'auPrefMt32Popup'
     237                                                type = 'PopUp'
     238                                />
     239                        </layout>
     240                        <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '6' center = 'true'>
     241                                <widget name = 'auPrefGmPopupDesc'
     242                                                type = 'OptionsLabel'
     243                                />
     244                                <widget name = 'auPrefGmPopup'
     245                                                type = 'PopUp'
     246                                />
     247                        </layout>
     248                        <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '6' center = 'true'>
    233249                                <widget name = 'auOPLPopupDesc'
    234250                                                type = 'OptionsLabel'
    235251                                />
  • gui/themes/scummmodern/scummmodern_layout.stx

     
    247247                                />
    248248                        </layout>
    249249                        <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10' center = 'true'>
     250                                <widget name = 'auPrefMt32PopupDesc'
     251                                                type = 'OptionsLabel'
     252                                />
     253                                <widget name = 'auPrefMt32Popup'
     254                                                type = 'PopUp'
     255                                />
     256                        </layout>
     257                        <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10' center = 'true'>
     258                                <widget name = 'auPrefGmPopupDesc'
     259                                                type = 'OptionsLabel'
     260                                />
     261                                <widget name = 'auPrefGmPopup'
     262                                                type = 'PopUp'
     263                                />
     264                        </layout>                       
     265                        <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '10' center = 'true'>
    250266                                <widget name = 'auOPLPopupDesc'
    251267                                                type = 'OptionsLabel'
    252268                                />
  • gui/themes/scummmodern/scummmodern_layout_lowres.stx

     
    228228                                />
    229229                        </layout>
    230230                        <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '6' center = 'true'>
     231                                <widget name = 'auPrefMt32PopupDesc'
     232                                                type = 'OptionsLabel'
     233                                />
     234                                <widget name = 'auPrefMt32Popup'
     235                                                type = 'PopUp'
     236                                />
     237                        </layout>
     238                        <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '6' center = 'true'>
     239                                <widget name = 'auPrefGmPopupDesc'
     240                                                type = 'OptionsLabel'
     241                                />
     242                                <widget name = 'auPrefGmPopup'
     243                                                type = 'PopUp'
     244                                />
     245                        </layout>
     246                        <layout type = 'horizontal' padding = '0, 0, 0, 0' spacing = '6' center = 'true'>
    231247                                <widget name = 'auOPLPopupDesc'
    232248                                                type = 'OptionsLabel'
    233249                                />
  • po/POTFILES

     
    2121engines/scumm/dialogs.cpp
    2222engines/mohawk/dialogs.cpp
    2323
    24 sound/mididrv.cpp
     24sound/musicplugin.cpp
     25sound/null.cpp
     26sound/softsynth/mt32.cpp
     27sound/softsynth/adlib.cpp
     28sound/softsynth/ym2612.cpp
    2529
    2630backends/keymapper/remap-dialog.cpp
    2731backends/platform/ds/arm9/source/dsoptions.cpp
  • sound/mididrv.cpp

     
    2727#include "common/config-manager.h"
    2828#include "common/str.h"
    2929#include "common/system.h"
    30 #include "common/translation.h"
    3130#include "common/util.h"
    3231#include "sound/mididrv.h"
     32#include "sound/musicplugin.h"
     33#include "common/translation.h"
    3334
    34 static const uint32 GUIOMapping[] = {
    35         MDT_PCSPK,      Common::GUIO_MIDIPCSPK,
    36         MDT_CMS,                Common::GUIO_MIDICMS,
    37         MDT_PCJR,               Common::GUIO_MIDIPCJR,
    38         MDT_ADLIB,      Common::GUIO_MIDIADLIB,
    39         MDT_TOWNS,      Common::GUIO_MIDITOWNS,
    40         MDT_MIDI,               Common::GUIO_MIDI,
    41         0,      0
    42 };
    43 
    44 uint32 MidiDriver::midiDriverFlags2GUIO(uint32 flags) {
    45         uint32 res = 0;
    46 
    47         for (int i = 0; GUIOMapping[i] || GUIOMapping[i + 1]; i += 2) {
    48                 if (flags & GUIOMapping[i])
    49                         res |= GUIOMapping[i + 1];
    50         }
    51 
    52         return res;
    53 }
    54 
    55 /** Internal list of all available 'midi' drivers. */
    56 static const MidiDriverDescription s_musicDrivers[] = {
    57 
    58         // The flags for the "auto" & "null" drivers indicate that they are anything
    59         // you want it to be.
    60         {"auto", _s("<default>"), MD_AUTO, MDT_MIDI | MDT_PCSPK | MDT_ADLIB | MDT_TOWNS},
    61         {"null", _s("No music"), MD_NULL, MDT_MIDI | MDT_PCSPK | MDT_ADLIB | MDT_TOWNS},
    62 
    63 #if defined(WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
    64         {"windows", _s("Windows MIDI"), MD_WINDOWS, MDT_MIDI},
    65 #endif
    66 
    67 #if defined(UNIX) && defined(USE_ALSA)
    68         {"alsa", _s("ALSA"), MD_ALSA, MDT_MIDI},
    69 #endif
    70 
    71 #if defined(__MINT__)
    72         {"stmidi", _s("Atari ST MIDI"), MD_STMIDI, MDT_MIDI},
    73 #endif
    74 
    75 #if defined(UNIX) && !defined(__BEOS__) && !defined(MACOSX) && !defined(__MAEMO__) && !defined(__MINT__)
    76         {"seq", _s("SEQ"), MD_SEQ, MDT_MIDI},
    77 #endif
    78 
    79 #if defined(IRIX)
    80         {"dmedia", _s("DMedia"), MD_DMEDIA, MDT_MIDI},
    81 #endif
    82 
    83 #if defined(__amigaos4__)
    84         {"camd", _s("CAMD"), MD_CAMD, MDT_MIDI},
    85 #endif
    86 
    87 #if defined(MACOSX)
    88         {"core", _s("CoreAudio"), MD_COREAUDIO, MDT_MIDI},
    89 //      {"coreaudio", "CoreAudio", MD_COREAUDIO, MDT_MIDI},
    90         {"coremidi", _s("CoreMIDI"), MD_COREMIDI, MDT_MIDI},
    91 #endif
    92 
    93 #if defined(PALMOS_MODE)
    94 #       if defined(COMPILE_CLIE)
    95         {"ypa1", _s("Yamaha Pa1"), MD_YPA1, MDT_MIDI},
    96 #       elif defined(COMPILE_ZODIAC) && (!defined(ENABLE_SCUMM) || !defined(PALMOS_ARM))
    97         {"zodiac", _s("Tapwave Zodiac"), MD_ZODIAC, MDT_MIDI},
    98 #       endif
    99 #endif
    100 
    101 #ifdef USE_FLUIDSYNTH
    102         {"fluidsynth", _s("FluidSynth"), MD_FLUIDSYNTH, MDT_MIDI},
    103 #endif
    104 #ifdef USE_MT32EMU
    105         {"mt32", _s("MT-32 Emulation"), MD_MT32, MDT_MIDI},
    106 #endif
    107 
    108         // The flags for the "adlib" driver indicates that it can do AdLib and MIDI.
    109         {"adlib", _s("AdLib"), MD_ADLIB, MDT_ADLIB},
    110         {"pcspk", _s("PC Speaker"), MD_PCSPK, MDT_PCSPK},
    111         {"pcjr", _s("IBM PCjr"), MD_PCJR, MDT_PCSPK | MDT_PCJR},
    112         {"cms", _s("Creative Music System"), MD_CMS, MDT_CMS},
    113         {"towns", _s("FM Towns"), MD_TOWNS, MDT_TOWNS},
    114 #if defined(UNIX)
    115         {"timidity", _s("TiMidity"), MD_TIMIDITY, MDT_MIDI},
    116 #endif
    117 
    118         {0, 0, MD_NULL, MDT_NONE}
    119 };
    120 
    12135const byte MidiDriver::_mt32ToGm[128] = {
    12236//        0    1    2    3    4    5    6    7    8    9    A    B    C    D    E    F
    12337          0,   1,   0,   2,   4,   4,   5,   3,  16,  17,  18,  16,  16,  19,  20,  21, // 0x
     
    14256        101, 103, 100, 120, 117, 113,  99, 128, 128, 128, 128, 124, 123, 128, 128, 128, // 7x
    14357};
    14458
    145 const MidiDriverDescription *MidiDriver::getAvailableMidiDrivers() {
    146         return s_musicDrivers;
    147 }
     59static const uint32 GUIOMapping[] = {
     60        MT_PCSPK,               Common::GUIO_MIDIPCSPK,
     61        /*MDT_CMS,              Common::GUIO_MIDICMS,*/
     62        MT_PCJR,                Common::GUIO_MIDIPCJR,
     63        MT_ADLIB,               Common::GUIO_MIDIADLIB,
     64        MT_TOWNS,               Common::GUIO_MIDITOWNS,
     65        MT_GM,                  Common::GUIO_MIDIGM,
     66        MT_MT32,                Common::GUIO_MIDIMT32, 
     67        0,              0
     68};
    14869
    149 const MidiDriverDescription *MidiDriver::findMusicDriver(const Common::String &str) {
    150         if (str.empty())
    151                 return 0;
     70uint32 MidiDriver::musicType2GUIO(uint32 musicType) {
     71        uint32 res = 0;
    15272
    153         const char *s = str.c_str();
    154         int len = 0;
    155         const MidiDriverDescription *md = s_musicDrivers;
     73        for (int i = 0; GUIOMapping[i] || GUIOMapping[i + 1]; i += 2) {
     74                if (musicType == GUIOMapping[i] || musicType == (uint32)-1)
     75                        res |= GUIOMapping[i + 1];
     76        }
    15677
    157         // Scan for string end or a colon
    158         while (s[len] != 0 && s[len] != ':')
    159                 len++;
     78        return res;
     79}
    16080
    161         while (md->name) {
    162                 // Compare the string passed to us with the current table entry.
    163                 // We ignore any characters following an (optional) colon ':'
    164                 // contained in str.
    165                 if (!scumm_strnicmp(md->name, s, len)) {
    166                         return md;
     81bool MidiDriver::_forceTypeMT32 = false;
     82
     83MusicType MidiDriver::getMusicType(MidiDriver::DeviceHandle handle) {
     84        if (_forceTypeMT32)
     85                return MT_MT32;
     86
     87        if (handle) {
     88                const MusicPlugin::List p = MusicMan.getPlugins();
     89                for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) {
     90                        MusicDevices i = (**m)->getDevices();
     91                        for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) {
     92                                if (handle == d->getHandle())
     93                                        return d->getMusicType();
     94                        }
    16795                }
    168                 md++;
    16996        }
    170 
    171         return 0;
     97       
     98        return MT_NULL;
    17299}
    173100
    174 static MidiDriverType getDefaultMIDIDriver() {
    175 #if defined(WIN32) && !defined(_WIN32_WCE) &&  !defined(__SYMBIAN32__)
    176         return MD_WINDOWS;
    177 #elif defined(MACOSX)
    178         return MD_COREAUDIO;
    179 #elif defined(PALMOS_MODE)
    180   #if defined(COMPILE_CLIE)
    181         return MD_YPA1;
    182   #elif defined(COMPILE_ZODIAC)
    183         return MD_ZODIAC;
    184   #else
    185         return MD_NULL;
    186   #endif
    187 #else
    188         return MD_NULL;
    189 #endif
    190 }
     101Common::String MidiDriver::getDeviceString(DeviceHandle handle, DeviceStringType type) {
     102        if (handle) {
     103                const MusicPlugin::List p = MusicMan.getPlugins();
     104                for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) {
     105                        MusicDevices i = (**m)->getDevices();
     106                        for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) {
     107                                if (handle == d->getHandle()) {
     108                                        if (type == kDriverName)
     109                                                return d->getMusicDriverName();
     110                                        else if (type == kDriverId)
     111                                                return d->getMusicDriverId();
     112                                        else if (type == kDeviceId)
     113                                                return d->getCompleteId();
     114                                        else
     115                                                return Common::String("auto");
     116                                }
     117                        }
     118                }
     119        }
    191120
    192 MidiDriverType MidiDriver::parseMusicDriver(const Common::String &str) {
    193         const MidiDriverDescription *md = findMusicDriver(str);
    194         if (md)
    195                 return md->id;
    196         return MD_AUTO;
     121        return Common::String("auto");
    197122}
    198123
    199 MidiDriverType MidiDriver::detectMusicDriver(int flags) {
    200         MidiDriverType musicDriver;
     124MidiDriver::DeviceHandle MidiDriver::detectDevice(int flags) {
     125        // Query the selected music device (defaults to MT_AUTO device).
     126        DeviceHandle hdl = getDeviceHandle(ConfMan.get("music_driver"));
    201127
    202         // Query the selected music driver (defaults to MD_AUTO).
    203         const MidiDriverDescription *md = findMusicDriver(ConfMan.get("music_driver"));
     128        _forceTypeMT32 = false;
    204129
    205130        // Check whether the selected music driver is compatible with the
    206131        // given flags.
    207         if (!md || !(md->flags & flags))
    208                 musicDriver = MD_AUTO;
    209         else
    210                 musicDriver = md->id;
     132        switch (getMusicType(hdl)) {
     133        case MT_PCSPK:
     134        case MT_PCJR:
     135                if (flags & MDT_PCSPK)
     136                        return hdl;
     137                break;
    211138
    212         // If the selected driver is MD_AUTO, we try to determine
    213         // a suitable and "optimal" music driver.
    214         if (musicDriver == MD_AUTO) {
     139        case MT_ADLIB:
     140                if (flags & MDT_ADLIB)
     141                        return hdl;
     142                break;
     143               
     144        case MT_TOWNS:
     145                if (flags & MDT_TOWNS)
     146                        return hdl;
     147                break;
    215148
    216                 if (flags & MDT_PREFER_MIDI) {
    217                         // A MIDI music driver is preferred. Of course this implies
    218                         // that MIDI is actually listed in flags, so we verify that.
    219                         assert(flags & MDT_MIDI);
     149        case MT_GM:
     150        case MT_GS:
     151        case MT_MT32:
     152                if (flags & MDT_MIDI)
     153                        return hdl;
     154        case MT_NULL:
     155                if (getDeviceString(hdl, MidiDriver::kDriverId).equals("null"))
     156                        return 0;
    220157
    221                         // Query the default MIDI driver. It's possible that there
    222                         // is none, in which case we revert to AUTO mode.
    223                         musicDriver = getDefaultMIDIDriver();
    224                         if (musicDriver == MD_NULL)
    225                                 musicDriver = MD_AUTO;
    226                 }
     158        default:
     159                break;
     160        }
    227161
    228                 if (musicDriver == MD_AUTO) {
    229                         // MIDI is not preferred, or no default MIDI device is available.
    230                         // In this case we first try the alternate drivers before checking
    231                         // for a 'real' MIDI driver.
     162        // If the selected driver did not match the flags setting,
     163        // we try to determine a suitable and "optimal" music driver.
     164        const MusicPlugin::List p = MusicMan.getPlugins();
     165        // If only MDT_MIDI but not MDT_PREFER_MIDI is set we prefer the other devices (which will always be
     166        // detected since they are hard coded and cannot be disabled.
     167        for (int l = (flags & MDT_PREFER_MIDI) ? 1 : 0; l < 2; l++) {
     168                if ((flags & MDT_MIDI) && (l == 1)) {
     169                        // If a preferred MT32 or GM device has been selected that device gets returned
     170                        hdl = getDeviceHandle(ConfMan.get((flags & MDT_PREFER_MT32) ? "mt32_device" : ((flags & MDT_PREFER_GM) ? "gm_device" : "auto"), Common::ConfigManager::kApplicationDomain));
     171                        if (getMusicType(hdl) != MT_NULL) {
     172                                if (flags & MDT_PREFER_MT32)
     173                                        // If we have a preferred MT32 device we disable the gm/mt32 mapping (more about this in mididrv.h)
     174                                        _forceTypeMT32 = true;
    232175
    233                         if (flags & MDT_TOWNS)
    234                                 musicDriver = MD_TOWNS;
    235                         else if (flags & MDT_ADLIB)
    236                                 musicDriver = MD_ADLIB;
    237                         else if (flags & MDT_PCSPK)
    238                                 musicDriver = MD_PCJR;
    239                         else if (flags & MDT_MIDI)
    240                                 musicDriver = getDefaultMIDIDriver();
    241                         else
    242                                 musicDriver = MD_NULL;
     176                                return hdl;
     177                        }
     178                       
     179                        // If we have no specific device selected (neither in the scummvm nor in the game domain)
     180                        // and no preferred MT32 or GM device selected we arrive here.
     181                        // If MT32 is preferred we try for the first available device with music type 'MT_MT32' (usually the mt32 emulator)
     182                        if (flags & MDT_PREFER_MT32) {
     183                                for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) {
     184                                        MusicDevices i = (**m)->getDevices();
     185                                        for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) {
     186                                                if (getMusicType(hdl) == MT_MT32)
     187                                                        return hdl;
     188                                        }
     189                                }
     190                        }
     191                       
     192                        // Now we default to the first available device with music type 'MT_GM'
     193                        for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) {
     194                                MusicDevices i = (**m)->getDevices();
     195                                for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) {
     196                                        if (getMusicType(hdl) == MT_GM || getMusicType(hdl) == MT_GS)
     197                                                return hdl;
     198                                }
     199                        }
     200                }
     201               
     202                MusicType tp = MT_NULL;
     203                if (flags & MDT_TOWNS)
     204                        tp = MT_TOWNS;
     205                else if (flags & MDT_ADLIB)
     206                        tp = MT_ADLIB;
     207                else if (flags & MDT_PCSPK)
     208                        tp = MT_PCSPK;
     209                else
     210                        tp = MT_NULL;
     211
     212                for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) {
     213                        MusicDevices i = (**m)->getDevices();
     214                        for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) {
     215                                if (d->getMusicType() == tp)
     216                                        return d->getHandle();
     217                        }
    243218                }
    244219        }
    245220
    246         return musicDriver;
     221        return hdl;
    247222}
    248223
    249 MidiDriver *MidiDriver::createMidi(MidiDriverType midiDriver) {
    250         switch (midiDriver) {
    251         case MD_NULL:      return MidiDriver_NULL_create();
    252 
    253         case MD_ADLIB:     return MidiDriver_ADLIB_create();
    254 
    255         case MD_TOWNS:     return MidiDriver_YM2612_create();
    256 
    257         // Right now PC Speaker and PCjr are handled
    258         // outside the MidiDriver architecture, so
    259         // don't create anything for now.
    260         case MD_PCSPK:
    261         case MD_CMS:
    262         case MD_PCJR:      return NULL;
    263 
    264 #ifdef USE_FLUIDSYNTH
    265         case MD_FLUIDSYNTH:     return MidiDriver_FluidSynth_create();
    266 #endif
    267 
    268 #ifdef USE_MT32EMU
    269         case MD_MT32:      return MidiDriver_MT32_create();
    270 #endif
    271 
    272 #if defined(PALMOS_MODE)
    273 #if defined(COMPILE_CLIE)
    274         case MD_YPA1:      return MidiDriver_YamahaPa1_create();
    275 #elif defined(COMPILE_ZODIAC) && (!defined(ENABLE_SCUMM) || !defined(PALMOS_ARM))
    276         case MD_ZODIAC:    return MidiDriver_Zodiac_create();
    277 #endif
    278 #endif
    279 
    280 #if defined(WIN32) && !defined(_WIN32_WCE) && !defined(__SYMBIAN32__)
    281         case MD_WINDOWS:   return MidiDriver_WIN_create();
    282 #endif
    283 #if defined(__MINT__)
    284         case MD_STMIDI:    return MidiDriver_STMIDI_create();
    285 #endif
    286 #if defined(UNIX) && !defined(__BEOS__) && !defined(MACOSX) && !defined(__MAEMO__) && !defined(__MINT__)
    287         case MD_SEQ:       return MidiDriver_SEQ_create();
    288 #endif
    289 #if defined(UNIX)
    290         case MD_TIMIDITY:  return MidiDriver_TIMIDITY_create();
    291 #endif
    292 #if defined(IRIX)
    293         case MD_DMEDIA:    return MidiDriver_DMEDIA_create();
    294 #endif
    295 #if defined(MACOSX)
    296         case MD_COREAUDIO: return MidiDriver_CORE_create();
    297         case MD_COREMIDI:  return MidiDriver_CoreMIDI_create();
    298 #endif
    299 #if defined(UNIX) && defined(USE_ALSA)
    300         case MD_ALSA:      return MidiDriver_ALSA_create();
    301 #endif
    302 #if defined(__amigaos4__)
    303         case MD_CAMD:      return MidiDriver_CAMD_create();
    304 #endif
    305         default:
    306                 error("Invalid midi driver selected");
     224MidiDriver *MidiDriver::createMidi(MidiDriver::DeviceHandle handle) {
     225        MidiDriver *driver = 0;
     226        const MusicPlugin::List p = MusicMan.getPlugins();
     227        for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) {
     228                if (getDeviceString(handle, MidiDriver::kDriverId).equals((**m)->getId()))
     229                        (**m)->createInstance(&driver, handle);
    307230        }
     231        return driver;
     232}
    308233
    309         return NULL;
     234MidiDriver::DeviceHandle MidiDriver::getDeviceHandle(const Common::String &identifier) {
     235        const MusicPlugin::List p = MusicMan.getPlugins();
     236        for (MusicPlugin::List::const_iterator m = p.begin(); m != p.end(); m++) {
     237                MusicDevices i = (**m)->getDevices();
     238                for (MusicDevices::iterator d = i.begin(); d != i.end(); d++) {
     239                        if (identifier.equals(d->getCompleteId()) || identifier.equals(d->getCompleteName()))
     240                                return d->getHandle();
     241                }
     242        }       
     243
     244        return getDeviceHandle("auto");
    310245}
  • sound/mididrv.h

     
    3030#include "common/timer.h"
    3131
    3232class MidiChannel;
     33class MusicDevice;
     34
    3335namespace Audio {
    3436        class Mixer;
    3537}
     
    4345 *
    4446 * @todo Rename MidiDriverType to MusicDriverType
    4547 */
    46 enum MidiDriverType {
    47         // Pseudo drivers
    48         MD_AUTO,
    49         MD_NULL,
    5048
    51         // Windows
    52         MD_WINDOWS,
    53 
    54         // Atari ST
    55         MD_STMIDI,
    56 
    57         // Linux
    58         MD_ALSA,
    59         MD_SEQ,
    60 
    61         // Mac OS X
    62         MD_QTMUSIC,
    63         MD_COREAUDIO,
    64         MD_COREMIDI,
    65 
    66         // PalmOS
    67         MD_YPA1,
    68         MD_ZODIAC,
    69 
    70         // IRIX
    71         MD_DMEDIA,
    72 
    73         // AMIGAOS4
    74         MD_CAMD,
    75 
    76         // MIDI softsynths
    77         MD_FLUIDSYNTH,
    78         MD_MT32,
    79 
    80         // "Fake" MIDI devices
    81         MD_ADLIB,
    82         MD_PCSPK,
    83         MD_CMS,
    84         MD_PCJR,
    85         MD_TOWNS,
    86         MD_TIMIDITY
     49/**
     50 * Music types that music drivers can implement and engines can rely on.
     51 */
     52enum MusicType {
     53        MT_NULL  = 0,  // Null / Auto
     54        MT_PCSPK = 1,  // PC Speaker
     55        MT_PCJR  = 2,  // PCjr
     56        MT_ADLIB = 3,  // AdLib
     57        MT_TOWNS = 4,  // FM-TOWNS
     58        MT_GM    = 5,  // General MIDI
     59        MT_MT32  = 6,  // MT-32
     60        MT_GS    = 7   // Roland GS
    8761};
    8862
    8963/**
    90  * A set of flags to be passed to detectMusicDriver() which can be used to
     64 * A set of flags to be passed to detectDevice() which can be used to
    9165 * specify what kind of music driver is preferred / accepted.
    9266 *
    9367 * The flags (except for MDT_PREFER_MIDI) indicate whether a given driver
    9468 * type is acceptable. E.g. the TOWNS music driver could be returned by
    95  * detectMusicDriver if and only if MDT_TOWNS is specified.
     69 * detectDevice if and only if MDT_TOWNS is specified.
    9670 *
    9771 * @todo Rename MidiDriverFlags to MusicDriverFlags
    9872 */
     
    10478        MDT_ADLIB  = 1 << 3,      // AdLib: Maps to MD_ADLIB
    10579        MDT_TOWNS  = 1 << 4,      // FM-TOWNS: Maps to MD_TOWNS
    10680        MDT_MIDI   = 1 << 5,      // Real MIDI
    107         MDT_PREFER_MIDI = 1 << 6  // Real MIDI output is preferred
     81        MDT_PREFER_MIDI = 1 << 6,  // Real MIDI output is preferred
     82        MDT_PREFER_MT32 = 1 << 7,  // MT-32 output is preferred
     83        MDT_PREFER_GM = 1 << 8  // GM output is preferred
    10884};
    10985
    11086/**
     
    11490 *
    11591 * @todo Rename MidiDriverType to MusicDriverType
    11692 */
    117 struct MidiDriverDescription {
    118         const char *name;
    119         const char *description;
    120         MidiDriverType id;              // A unique ID for each driver
    121         int flags;                              // Capabilities of this driver
    122 };
    12393
    12494/**
    12595 * Abstract MIDI Driver Class
     
    12898 */
    12999class MidiDriver {
    130100public:
    131         /** Find the music driver matching the given driver name/description. */
    132         static const MidiDriverDescription *findMusicDriver(const Common::String &str);
     101        typedef uint32 DeviceHandle;
    133102
    134         /** Get the id of the music driver matching the given driver name, or MD_AUTO if there is no match. */
    135         static MidiDriverType parseMusicDriver(const Common::String &str);
     103        enum DeviceStringType {
     104                kDriverName,
     105                kDriverId,
     106                kDeviceId
     107        };
    136108
    137         static uint32 midiDriverFlags2GUIO(uint32 flags);
     109        static uint32 musicType2GUIO(uint32 musicType);
    138110
     111        /** Create music driver matching the given device handle, or MT_AUTO if there is no match. */
     112        static MidiDriver *createMidi(DeviceHandle handle);
     113
     114        /** Returnd device handle based on the present devices and the flags parameter.
     115        / *     Returns NULl if the matching device is the null or auto device. */
     116        static DeviceHandle detectDevice(int flags);
     117               
    139118        /**
    140          * Get a list of all available MidiDriver types.
    141          * @return list of all available midi drivers, terminated by  a zero entry
     119         * Find the music driver matching the given driver name/description.
    142120         */
    143         static const MidiDriverDescription *getAvailableMidiDrivers();
     121        static DeviceHandle getDeviceHandle(const Common::String &identifier);
    144122
    145         static MidiDriver *createMidi(MidiDriverType midiDriver);
     123        /** Get the music type matching the given device handle, or MT_AUTO if there is no match. */
     124        static MusicType getMusicType(DeviceHandle handle);
    146125
    147         static MidiDriverType detectMusicDriver(int flags);
     126        /** Get the device string matching the given device handle and the given type. */
     127        static Common::String getDeviceString(DeviceHandle handle, DeviceStringType type);
    148128
     129private:
     130        // If detectDevice() detects MT32 and we have a preferred MT32 device
     131        // we use this to force getMusicType() to return MT_MT32 so that we don't
     132        // have to rely on the 'True Roland MT-32' config manager setting (since nobody
     133        // would possibly think about activating 'True Roland MT-32' when he has set
     134        // 'Music Driver' to '>default>')
     135        static bool _forceTypeMT32;
    149136
    150137public:
    151138        virtual ~MidiDriver() { }
     
    274261        virtual void sysEx_customInstrument(uint32 type, const byte *instr) = 0;
    275262};
    276263
    277 
    278 // Factory functions, for faster compile
    279 extern MidiDriver *MidiDriver_NULL_create();
    280 extern MidiDriver *MidiDriver_ADLIB_create();
    281 extern MidiDriver *MidiDriver_WIN_create();
    282 extern MidiDriver *MidiDriver_STMIDI_create();
    283 extern MidiDriver *MidiDriver_SEQ_create();
    284 extern MidiDriver *MidiDriver_TIMIDITY_create();
    285 extern MidiDriver *MidiDriver_QT_create();
    286 extern MidiDriver *MidiDriver_CORE_create();
    287 extern MidiDriver *MidiDriver_CoreMIDI_create();
    288 extern MidiDriver *MidiDriver_ALSA_create();
    289 extern MidiDriver *MidiDriver_DMEDIA_create();
    290 extern MidiDriver *MidiDriver_CAMD_create();
    291 extern MidiDriver *MidiDriver_YM2612_create();
    292 #ifdef USE_FLUIDSYNTH
    293 extern MidiDriver *MidiDriver_FluidSynth_create();
    294264#endif
    295 #ifdef USE_MT32EMU
    296 extern MidiDriver *MidiDriver_MT32_create();
    297 #endif
    298 extern MidiDriver *MidiDriver_YamahaPa1_create();
    299 extern MidiDriver *MidiDriver_Zodiac_create();
    300 
    301 #endif
  • sound/musicplugin.cpp

     
    2424 */
    2525
    2626#include "sound/musicplugin.h"
     27#include "common/hash-str.h"
     28#include "common/translation.h"
    2729
    2830MusicDevice::MusicDevice(MusicPluginObject const *musicPlugin, Common::String name, MusicType mt) :
    29         _musicDriverName(musicPlugin->getName()), _musicDriverId(musicPlugin->getId()),
    30         _name(name), _type(mt) {
     31        _musicDriverName(_(musicPlugin->getName())), _musicDriverId(musicPlugin->getId()),
     32        _name(_(name)), _type(mt) {
    3133}
    3234
    3335Common::String MusicDevice::getCompleteName() {
     
    4648
    4749        return name;
    4850}
     51
     52Common::String MusicDevice::getCompleteId() {
     53        Common::String id = _musicDriverId;
     54        if (!_name.empty()) {
     55                id += "_";
     56                id += _name;
     57        }
     58
     59        return id;
     60}
     61
     62MidiDriver::DeviceHandle MusicDevice::getHandle() {
     63        if (_musicDriverId.equals("auto") || _musicDriverId.equals("null"))
     64                return 0;
     65        return (MidiDriver::DeviceHandle)Common::hashit(getCompleteId().c_str());
     66}
  • sound/musicplugin.h

     
    2929#include "sound/mididrv.h"
    3030#include "common/list.h"
    3131
    32 /**
    33  * Music types that music drivers can implement and engines can rely on.
    34  */
    35 enum MusicType {
    36         MT_PCSPK = 1,  // PC Speaker
    37         MT_PCJR  = 2,  // PCjr
    38         MT_ADLIB = 3,  // AdLib
    39         MT_TOWNS = 4,  // FM-TOWNS
    40         MT_GM    = 5,  // General MIDI
    41         MT_MT32  = 6,  // MT-32
    42         MT_GS    = 7   // Roland GS
    43 };
    44 
    4532class MusicPluginObject;
    4633
    4734/**
     
    6350         * device name (if it isn't the default one) and the name of the driver.
    6451         */
    6552        Common::String getCompleteName();
     53       
     54        /**
     55         * Returns a user readable string that contains the name of the current
     56         * device name (if it isn't the default one) and the id of the driver.
     57         */
     58        Common::String getCompleteId();
    6659
     60        MidiDriver::DeviceHandle getHandle();
     61
    6762private:
    6863        Common::String _name;
    6964        Common::String _musicDriverName;
     
    9489        virtual MusicDevices getDevices() const = 0;
    9590
    9691        /**
    97          * Tries to instantiate a MIDI Driver instance based on the settings of
    98          * the currently active ConfMan target. That is, the MusicPluginObject
    99          * should query the ConfMan singleton for the device name, port, etc.
     92         * Tries to instantiate a MIDI Driver instance based on the device
     93         * previously detected via MidiDriver::detectDevice()
    10094         *
    10195         * @param mididriver    Pointer to a pointer which the MusicPluginObject sets
    10296         *                              to the newly create MidiDriver, or 0 in case of an error
     97         *
     98        * @param dev    Pointer to a device to be used then creating the driver instance.
     99         *                              Default value of zero for driver types without devices.
     100         *
    103101         * @return              a Common::Error describing the error which occurred, or kNoError
    104102         */
    105         virtual Common::Error createInstance(MidiDriver **mididriver) const = 0;
     103        virtual Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const = 0;
    106104};
    107105
    108106
  • sound/null.cpp

     
    2424
    2525#include "sound/musicplugin.h"
    2626#include "sound/mpu401.h"
     27#include "common/translation.h"
    2728
    2829/* NULL driver */
    2930class MidiDriver_NULL : public MidiDriver_MPU401 {
     
    3738
    3839class NullMusicPlugin : public MusicPluginObject {
    3940public:
    40         const char *getName() const {
    41                 return "No music";
     41        virtual const char *getName() const {
     42                return _s("No music");
    4243        }
    4344
    44         const char *getId() const {
     45        virtual const char *getId() const {
    4546                return "null";
    4647        }
    4748
    48         MusicDevices getDevices() const;
    49         Common::Error createInstance(MidiDriver **mididriver) const;
     49        virtual MusicDevices getDevices() const;
     50        virtual Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
    5051};
    5152
    52 Common::Error NullMusicPlugin::createInstance(MidiDriver **mididriver) const {
     53Common::Error NullMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
    5354        *mididriver = new MidiDriver_NULL();
    5455
    5556        return Common::kNoError;
     
    5758
    5859MusicDevices NullMusicPlugin::getDevices() const {
    5960        MusicDevices devices;
    60         // TODO: return a different music type?
    61         devices.push_back(MusicDevice(this, "", MT_GM));
     61        devices.push_back(MusicDevice(this, _s(""), MT_NULL));
    6262        return devices;
    6363}
    6464
    65 MidiDriver *MidiDriver_NULL_create() {
    66         MidiDriver *mididriver;
     65class AutoMusicPlugin : public NullMusicPlugin {
     66public:
     67        const char *getName() const {
     68                return _s("<default>");
     69        }
    6770
    68         NullMusicPlugin p;
    69         p.createInstance(&mididriver);
     71        const char *getId() const {
     72                return "auto";
     73        }
     74};
    7075
    71         return mididriver;
    72 }
    73 
    74 #ifdef DISABLE_ADLIB
    75 MidiDriver *MidiDriver_ADLIB_create() {
    76         return MidiDriver_NULL_create();
    77 }
    78 #endif
    79 
    8076//#if PLUGIN_ENABLED_DYNAMIC(NULL)
    8177        //REGISTER_PLUGIN_DYNAMIC(NULL, PLUGIN_TYPE_MUSIC, NullMusicPlugin);
    8278//#else
     79        REGISTER_PLUGIN_STATIC(AUTO, PLUGIN_TYPE_MUSIC, AutoMusicPlugin);
    8380        REGISTER_PLUGIN_STATIC(NULL, PLUGIN_TYPE_MUSIC, NullMusicPlugin);
    8481//#endif
  • sound/softsynth/adlib.cpp

     
    2727#include "common/util.h"
    2828#include "sound/fmopl.h"
    2929#include "sound/musicplugin.h"
     30#include "common/translation.h"
    3031
    3132#ifdef DEBUG_ADLIB
    3233static int tick;
     
    15861587class AdLibEmuMusicPlugin : public MusicPluginObject {
    15871588public:
    15881589        const char *getName() const {
    1589                 return "AdLib Emulator";
     1590                return _s("AdLib Emulator");
    15901591        }
    15911592
    15921593        const char *getId() const {
     
    15941595        }
    15951596
    15961597        MusicDevices getDevices() const;
    1597         Common::Error createInstance(MidiDriver **mididriver) const;
     1598        Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
    15981599};
    15991600
    16001601MusicDevices AdLibEmuMusicPlugin::getDevices() const {
     
    16031604        return devices;
    16041605}
    16051606
    1606 Common::Error AdLibEmuMusicPlugin::createInstance(MidiDriver **mididriver) const {
     1607Common::Error AdLibEmuMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
    16071608        *mididriver = new MidiDriver_ADLIB(g_system->getMixer());
    16081609
    16091610        return Common::kNoError;
    16101611}
    16111612
    1612 MidiDriver *MidiDriver_ADLIB_create() {
    1613         MidiDriver *mididriver;
    1614 
    1615         AdLibEmuMusicPlugin p;
    1616         p.createInstance(&mididriver);
    1617 
    1618         return mididriver;
    1619 }
    1620 
    16211613//#if PLUGIN_ENABLED_DYNAMIC(ADLIB)
    16221614        //REGISTER_PLUGIN_DYNAMIC(ADLIB, PLUGIN_TYPE_MUSIC, AdLibEmuMusicPlugin);
    16231615//#else
  • sound/softsynth/fluidsynth.cpp

     
    230230        }
    231231
    232232        MusicDevices getDevices() const;
    233         Common::Error createInstance(MidiDriver **mididriver) const;
     233        Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
    234234};
    235235
    236236MusicDevices FluidSynthMusicPlugin::getDevices() const {
     
    239239        return devices;
    240240}
    241241
    242 Common::Error FluidSynthMusicPlugin::createInstance(MidiDriver **mididriver) const {
     242Common::Error FluidSynthMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
    243243        *mididriver = new MidiDriver_FluidSynth(g_system->getMixer());
    244244
    245245        return Common::kNoError;
    246246}
    247247
    248 MidiDriver *MidiDriver_FluidSynth_create() {
    249         MidiDriver *mididriver;
    250 
    251         FluidSynthMusicPlugin p;
    252         p.createInstance(&mididriver);
    253 
    254         return mididriver;
    255 }
    256 
    257248//#if PLUGIN_ENABLED_DYNAMIC(FLUIDSYNTH)
    258249        //REGISTER_PLUGIN_DYNAMIC(FLUIDSYNTH, PLUGIN_TYPE_MUSIC, FluidSynthMusicPlugin);
    259250//#else
  • sound/softsynth/mt32.cpp

     
    3939#include "common/system.h"
    4040#include "common/util.h"
    4141#include "common/archive.h"
     42#include "common/translation.h"
    4243
    4344#include "graphics/fontman.h"
    4445#include "graphics/surface.h"
     
    323324        }
    324325
    325326        _initialising = true;
    326         drawMessage(-1, "Initialising MT-32 Emulator");
     327        drawMessage(-1, _s("Initialising MT-32 Emulator"));
    327328        if (!_synth->open(prop))
    328329                return MERR_DEVICE_NOT_AVAILABLE;
    329330        _initialising = false;
     
    537538class MT32EmuMusicPlugin : public MusicPluginObject {
    538539public:
    539540        const char *getName() const {
    540                 return "MT-32 Emulator";
     541                return _s("MT-32 Emulator");
    541542        }
    542543
    543544        const char *getId() const {
     
    545546        }
    546547
    547548        MusicDevices getDevices() const;
    548         Common::Error createInstance(MidiDriver **mididriver) const;
     549        Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
    549550};
    550551
    551552MusicDevices MT32EmuMusicPlugin::getDevices() const {
     
    554555        return devices;
    555556}
    556557
    557 Common::Error MT32EmuMusicPlugin::createInstance(MidiDriver **mididriver) const {
    558         *mididriver = new MidiDriver_MT32(g_system->getMixer());
    559 
    560         return Common::kNoError;
    561 }
    562 
    563 MidiDriver *MidiDriver_MT32_create() {
    564         // HACK: It will stay here until engine plugin loader overhaul
     558Common::Error MT32EmuMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
    565559        if (ConfMan.hasKey("extrapath"))
    566560                SearchMan.addDirectory("extrapath", ConfMan.get("extrapath"));
    567561
    568         MidiDriver *mididriver;
     562        *mididriver = new MidiDriver_MT32(g_system->getMixer());
    569563
    570         MT32EmuMusicPlugin p;
    571         p.createInstance(&mididriver);
    572 
    573         return mididriver;
     564        return Common::kNoError;
    574565}
    575566
    576567//#if PLUGIN_ENABLED_DYNAMIC(MT32)
  • sound/softsynth/ym2612.cpp

     
    2727#include "sound/softsynth/ym2612.h"
    2828#include "common/util.h"
    2929#include "sound/musicplugin.h"
     30#include "common/translation.h"
    3031
    3132////////////////////////////////////////
    3233//
     
    758759class TownsEmuMusicPlugin : public MusicPluginObject {
    759760public:
    760761        const char *getName() const {
    761                 return "FM Towns Emulator";
     762                return _s("FM Towns Emulator");
    762763        }
    763764
    764765        const char *getId() const {
     
    766767        }
    767768
    768769        MusicDevices getDevices() const;
    769         Common::Error createInstance(MidiDriver **mididriver) const;
     770        Common::Error createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle = 0) const;
    770771};
    771772
    772773MusicDevices TownsEmuMusicPlugin::getDevices() const {
     
    775776        return devices;
    776777}
    777778
    778 Common::Error TownsEmuMusicPlugin::createInstance(MidiDriver **mididriver) const {
     779Common::Error TownsEmuMusicPlugin::createInstance(MidiDriver **mididriver, MidiDriver::DeviceHandle) const {
    779780        *mididriver = new MidiDriver_YM2612(g_system->getMixer());
    780781
    781782        return Common::kNoError;
    782783}
    783784
    784 MidiDriver *MidiDriver_YM2612_create() {
    785         MidiDriver *mididriver;
    786 
    787         TownsEmuMusicPlugin p;
    788         p.createInstance(&mididriver);
    789 
    790         return mididriver;
    791 }
    792 
    793785//#if PLUGIN_ENABLED_DYNAMIC(TOWNS)
    794786        //REGISTER_PLUGIN_DYNAMIC(TOWNS, PLUGIN_TYPE_MUSIC, TownsEmuMusicPlugin);
    795787//#else