diff options
author | Max Horn | 2002-12-11 16:09:58 +0000 |
---|---|---|
committer | Max Horn | 2002-12-11 16:09:58 +0000 |
commit | bf62494fd5fc578a609b5986237035997c214b15 (patch) | |
tree | 68c3f90d9ddd0f93fafc1c84548e611d458d88de /backends/midi | |
parent | 5bf87dd3682af7de77fd0fff8d182087ebc8151a (diff) | |
download | scummvm-rg350-bf62494fd5fc578a609b5986237035997c214b15.tar.gz scummvm-rg350-bf62494fd5fc578a609b5986237035997c214b15.tar.bz2 scummvm-rg350-bf62494fd5fc578a609b5986237035997c214b15.zip |
ripped out obsolete midi streaming code from backends (this may break Alsa/SEQ/Windows/Morphos compile, I tried my best, but you'll have to clean up after me)
svn-id: r5905
Diffstat (limited to 'backends/midi')
-rw-r--r-- | backends/midi/adlib.cpp | 21 | ||||
-rw-r--r-- | backends/midi/alsa.cpp | 82 | ||||
-rw-r--r-- | backends/midi/coreaudio.cpp | 15 | ||||
-rw-r--r-- | backends/midi/null.cpp | 6 | ||||
-rw-r--r-- | backends/midi/quicktime.cpp | 30 | ||||
-rw-r--r-- | backends/midi/windows.cpp | 196 |
6 files changed, 62 insertions, 288 deletions
diff --git a/backends/midi/adlib.cpp b/backends/midi/adlib.cpp index affa88afd8..dfa3d9aab1 100644 --- a/backends/midi/adlib.cpp +++ b/backends/midi/adlib.cpp @@ -488,11 +488,9 @@ class MidiDriver_ADLIB : public MidiDriver { public: MidiDriver_ADLIB(); - int open(int mode); + int open(); void close(); void send(uint32 b); - void pause(bool p) { } - void set_stream_callback(void *param, StreamCallback *sc) { } // No streaming support. Use MidiStreamer wrapper uint32 property (int prop, uint32 param); void setPitchBendRange (byte channel, uint range); @@ -511,7 +509,7 @@ public: MidiChannel *getPercussionChannel() { return NULL; } // Percussion currently not supported private: - int _mode; + bool _isOpen; bool _game_SmallHeader; FM_OPL *_opl; @@ -720,15 +718,14 @@ MidiDriver_ADLIB::MidiDriver_ADLIB() _parts[i].init (this); } _game_SmallHeader = false; + _isOpen = false; } -int MidiDriver_ADLIB::open (int mode) +int MidiDriver_ADLIB::open () { - if (_mode != 0) + if (_isOpen) return MERR_ALREADY_OPEN; - if (mode != MO_SIMPLE) - return MERR_STREAMING_NOT_AVAILABLE; - _mode = mode; + _isOpen = true; int i; MidiChannelAdl *mc; @@ -750,6 +747,7 @@ int MidiDriver_ADLIB::open (int mode) _mixer = g_mixer; _mixer->setupPremix(this, premix_proc); + return 0; } @@ -763,13 +761,12 @@ void MidiDriver_ADLIB::close() // Detach the premix callback handler _mixer->setupPremix (0, 0); + + _isOpen = false; } void MidiDriver_ADLIB::send (uint32 b) { - if (_mode != MO_SIMPLE) - error("MidiDriver_ADLIB::send called but driver is not in simple mode"); - //byte param3 = (byte) ((b >> 24) & 0xFF); byte param2 = (byte) ((b >> 16) & 0xFF); byte param1 = (byte) ((b >> 8) & 0xFF); diff --git a/backends/midi/alsa.cpp b/backends/midi/alsa.cpp index 538b0cd74b..c150dc11a8 100644 --- a/backends/midi/alsa.cpp +++ b/backends/midi/alsa.cpp @@ -51,72 +51,33 @@ class MidiDriver_ALSA:public MidiDriver_MPU401 { public: MidiDriver_ALSA(); - int open(int mode); + int open(); void close(); void send(uint32 b); - void pause(bool p); - void set_stream_callback(void *param, StreamCallback *sc); - // void setPitchBendRange (byte channel, uint range); private: void send_event(int do_flush); + bool _isOpen; snd_seq_event_t ev; - StreamCallback *_stream_proc; - void *_stream_param; - int _mode; snd_seq_t *seq_handle; int seq_client, seq_port; int my_client, my_port; static int parse_addr(char *arg, int *client, int *port); }; -MidiDriver_ALSA::MidiDriver_ALSA():_mode(0), seq_handle(0), seq_client(0), seq_port(0), my_client(0), -my_port(0) +MidiDriver_ALSA::MidiDriver_ALSA() + : _isOpen(false), seq_handle(0), seq_client(0), seq_port(0), my_client(0), my_port(0) { } -int MidiDriver_ALSA::parse_addr(char *arg, int *client, int *port) -{ - char *p; - - if (isdigit(*arg)) { - if ((p = strpbrk(arg, ADDR_DELIM)) == NULL) - return -1; - *client = atoi(arg); - *port = atoi(p + 1); - } else { - if (*arg == 's' || *arg == 'S') { - *client = SND_SEQ_ADDRESS_SUBSCRIBERS; - *port = 0; - } else - return -1; - } - return 0; -} - -void MidiDriver_ALSA::send_event(int do_flush) -{ - snd_seq_ev_set_direct(&ev); - snd_seq_ev_set_source(&ev, my_port); - snd_seq_ev_set_dest(&ev, seq_client, seq_port); - - snd_seq_event_output(seq_handle, &ev); - if (do_flush) - snd_seq_flush_output(seq_handle); -} - -int MidiDriver_ALSA::open(int mode) +int MidiDriver_ALSA::open() { char *var; unsigned int caps; - if (_mode != 0) + if (_isOpen) return MERR_ALREADY_OPEN; - - if (mode != MO_SIMPLE) - return MERR_STREAMING_NOT_AVAILABLE; - - _mode = mode; + _isOpen = true; if (!(var = getenv("SCUMMVM_PORT"))) { // default alsa port if none specified @@ -225,17 +186,34 @@ void MidiDriver_ALSA::send(uint32 b) } } -void MidiDriver_ALSA::pause(bool p) +int MidiDriver_ALSA::parse_addr(char *arg, int *client, int *port) { - if (_mode == MO_STREAMING) { - /* Err... and what? */ + char *p; + + if (isdigit(*arg)) { + if ((p = strpbrk(arg, ADDR_DELIM)) == NULL) + return -1; + *client = atoi(arg); + *port = atoi(p + 1); + } else { + if (*arg == 's' || *arg == 'S') { + *client = SND_SEQ_ADDRESS_SUBSCRIBERS; + *port = 0; + } else + return -1; } + return 0; } -void MidiDriver_ALSA::set_stream_callback(void *param, StreamCallback *sc) +void MidiDriver_ALSA::send_event(int do_flush) { - _stream_param = param; - _stream_proc = sc; + snd_seq_ev_set_direct(&ev); + snd_seq_ev_set_source(&ev, my_port); + snd_seq_ev_set_dest(&ev, seq_client, seq_port); + + snd_seq_event_output(seq_handle, &ev); + if (do_flush) + snd_seq_flush_output(seq_handle); } MidiDriver *MidiDriver_ALSA_create() diff --git a/backends/midi/coreaudio.cpp b/backends/midi/coreaudio.cpp index 00cc81e4f5..879162290e 100644 --- a/backends/midi/coreaudio.cpp +++ b/backends/midi/coreaudio.cpp @@ -39,30 +39,21 @@ class MidiDriver_CORE : public MidiDriver_MPU401 { public: MidiDriver_CORE() : au_MusicDevice(0), au_output(0) { } - int open(int mode); + int open(); void close(); void send(uint32 b); - void pause(bool p) { } - void set_stream_callback(void *param, StreamCallback *sc) { } private: AudioUnit au_MusicDevice; AudioUnit au_output; - - int _mode; }; -int MidiDriver_CORE::open(int mode) +int MidiDriver_CORE::open() { if (au_output != NULL) return MERR_ALREADY_OPEN; - if (mode == MO_STREAMING) - return MERR_STREAMING_NOT_AVAILABLE; - - _mode = mode; - int err; AudioUnitConnection auconnect; ComponentDescription compdesc; @@ -106,8 +97,6 @@ void MidiDriver_CORE::close() // Cleanup CloseComponent(au_output); CloseComponent(au_MusicDevice); - - _mode = 0; } void MidiDriver_CORE::send(uint32 b) diff --git a/backends/midi/null.cpp b/backends/midi/null.cpp index 80e30735c2..74612d18cf 100644 --- a/backends/midi/null.cpp +++ b/backends/midi/null.cpp @@ -25,14 +25,12 @@ /* NULL driver */ class MidiDriver_NULL : public MidiDriver_MPU401 { public: - int open(int mode); + int open(); void close() { } void send(uint32 b) { } - void pause(bool p) { } - void set_stream_callback(void *param, StreamCallback *sc) { } }; -int MidiDriver_NULL::open(int mode) +int MidiDriver_NULL::open() { warning("Music not enabled - MIDI support selected with no MIDI driver available. Try Adlib"); return 0; diff --git a/backends/midi/quicktime.cpp b/backends/midi/quicktime.cpp index f08f3e2d79..e447208bf0 100644 --- a/backends/midi/quicktime.cpp +++ b/backends/midi/quicktime.cpp @@ -46,11 +46,11 @@ */ class MidiDriver_QT : public MidiDriver_MPU401 { public: - int open(int mode); + MidiDriver_QT(); + + int open(); void close(); void send(uint32 b); - void pause(bool p) { } - void set_stream_callback(void *param, StreamCallback *sc); void setPitchBendRange (byte channel, uint range); private: @@ -58,33 +58,24 @@ private: NoteChannel qtNoteChannel[16]; NoteRequest simpleNoteRequest; - StreamCallback *_stream_proc; - void *_stream_param; - int _mode; - // Pitch bend tracking. Necessary since QTMA handles // pitch bending so differently from MPU401. uint16 _pitchbend [16]; byte _pitchbend_range [16]; }; -void MidiDriver_QT::set_stream_callback(void *param, StreamCallback *sc) +MidiDriver_QT::MidiDriver_QT() { - _stream_param = param; - _stream_proc = sc; + qtNoteAllocator = NULL; } -int MidiDriver_QT::open(int mode) +int MidiDriver_QT::open() { ComponentResult qtErr = noErr; int i; - qtNoteAllocator = NULL; - - if (mode == MO_STREAMING) - return MERR_STREAMING_NOT_AVAILABLE; - - _mode = mode; + if (qtNoteAllocator != NULL) + return MERR_ALREADY_OPEN; for (i = 0; i < 15; i++) qtNoteChannel[i] = NULL; @@ -126,8 +117,6 @@ bail: void MidiDriver_QT::close() { - _mode = 0; - for (int i = 0; i < 15; i++) { if (qtNoteChannel[i] != NULL) NADisposeNoteChannel(qtNoteAllocator, qtNoteChannel[i]); @@ -142,9 +131,6 @@ void MidiDriver_QT::close() void MidiDriver_QT::send(uint32 b) { - if (_mode != MO_SIMPLE) - error("MidiDriver_QT:send called but driver is not in simple mode"); - MusicMIDIPacket midPacket; unsigned char *midiCmd = midPacket.data; midPacket.length = 3; diff --git a/backends/midi/windows.cpp b/backends/midi/windows.cpp index e49c62bf27..10653eb928 100644 --- a/backends/midi/windows.cpp +++ b/backends/midi/windows.cpp @@ -32,189 +32,41 @@ class MidiDriver_WIN : public MidiDriver_MPU401 { public: + MidiDriver_WIN(); int open(int mode); void close(); void send(uint32 b); - void pause(bool p); - void set_stream_callback(void *param, StreamCallback *sc); private: - struct MyMidiHdr { - MIDIHDR hdr; - }; - - enum { - NUM_PREPARED_HEADERS = 2, - MIDI_EVENT_SIZE = 64, - BUFFER_SIZE = MIDI_EVENT_SIZE * 12, - }; - - StreamCallback *_stream_proc; - void *_stream_param; - int _mode; - HMIDIOUT _mo; - HMIDISTRM _ms; - - MyMidiHdr *_prepared_headers; - uint16 _time_div; - - void unprepare(); - void prepare(); void check_error(MMRESULT result); - void fill_all(); uint32 property(int prop, uint32 param); - - static void CALLBACK midi_callback(HMIDIOUT hmo, UINT wMsg, - DWORD dwInstance, DWORD dwParam1, DWORD dwParam2); }; -void MidiDriver_WIN::set_stream_callback(void *param, StreamCallback *sc) -{ - _stream_param = param; - _stream_proc = sc; -} - -void CALLBACK MidiDriver_WIN::midi_callback(HMIDIOUT hmo, UINT wMsg, - DWORD dwInstance, DWORD dwParam1, DWORD dwParam2) +MidiDriver_WIN::MidiDriver_WIN() { - switch (wMsg) { - case MM_MOM_DONE:{ - MidiDriver_WIN *md = ((MidiDriver_WIN *) dwInstance); - if (md->_mode) - md->fill_all(); - break; - } - } + _isOpen = false; } -int MidiDriver_WIN::open(int mode) +int MidiDriver_WIN::open() { - if (_mode != 0) + if (_isOpen) return MERR_ALREADY_OPEN; - _mode = mode; - - if (mode == MO_SIMPLE) { - MMRESULT res = midiOutOpen((HMIDIOUT *) & _mo, MIDI_MAPPER, 0, 0, 0); - if (res != MMSYSERR_NOERROR) - check_error(res); - } else { - // Streaming mode - MIDIPROPTIMEDIV mptd; - UINT _midi_device_id = 0; - - check_error(midiStreamOpen(&_ms, &_midi_device_id, 1, - (uint32)midi_callback, (uint32)this, CALLBACK_FUNCTION)); - - prepare(); - - mptd.cbStruct = sizeof(mptd); - mptd.dwTimeDiv = _time_div; + _isOpen = true; - check_error(midiStreamProperty(_ms, (byte *)&mptd, MIDIPROP_SET | MIDIPROP_TIMEDIV)); - - fill_all(); - } + MMRESULT res = midiOutOpen((HMIDIOUT *) &_mo, MIDI_MAPPER, 0, 0, 0); + if (res != MMSYSERR_NOERROR) + check_error(res); return 0; } -void MidiDriver_WIN::fill_all() -{ - if (_stream_proc == NULL) { - error("MidiDriver_WIN::fill_all() called, but _stream_proc==NULL"); - } - - uint i; - MyMidiHdr *mmh = _prepared_headers; - MidiEvent my_evs[64]; - - for (i = 0; i != NUM_PREPARED_HEADERS; i++, mmh++) { - if (!(mmh->hdr.dwFlags & MHDR_INQUEUE)) { - int num = _stream_proc(_stream_param, my_evs, 64); - int i; - - // End of stream? - if (num == 0) - break; - - MIDIEVENT *ev = (MIDIEVENT *)mmh->hdr.lpData; - MidiEvent *my_ev = my_evs; - - for (i = 0; i != num; i++, my_ev++) { - ev->dwStreamID = 0; - ev->dwDeltaTime = my_ev->delta; - - switch (my_ev->event >> 24) { - case 0: - ev->dwEvent = my_ev->event; - break; - case ME_TEMPO: - // Change tempo event - ev->dwEvent = (ME_TEMPO << 24) | (my_ev->event & 0xFFFFFF); - break; - default: - error("Invalid event type passed"); - } - - // Increase stream pointer by 12 bytes. - // (Need to be 12 bytes, and sizeof(MIDIEVENT) is 16) - ev = (MIDIEVENT *)((byte *)ev + 12); - } - - mmh->hdr.dwBytesRecorded = num * 12; - check_error(midiStreamOut(_ms, &mmh->hdr, sizeof(mmh->hdr))); - } - } -} - -void MidiDriver_WIN::prepare() -{ - int i; - MyMidiHdr *mmh; - - _prepared_headers = (MyMidiHdr *) calloc(sizeof(MyMidiHdr), 2); - - for (i = 0, mmh = _prepared_headers; i != NUM_PREPARED_HEADERS; i++, mmh++) { - mmh->hdr.dwBufferLength = BUFFER_SIZE; - mmh->hdr.lpData = (LPSTR) calloc(BUFFER_SIZE, 1); - - check_error(midiOutPrepareHeader((HMIDIOUT) _ms, &mmh->hdr, sizeof(mmh->hdr))); - } -} - -void MidiDriver_WIN::unprepare() -{ - uint i; - MyMidiHdr *mmh = _prepared_headers; - - for (i = 0; i != NUM_PREPARED_HEADERS; i++, mmh++) { - check_error(midiOutUnprepareHeader((HMIDIOUT) _ms, &mmh->hdr, sizeof(mmh->hdr))); - free(mmh->hdr.lpData); - mmh->hdr.lpData = NULL; - } - - free(_prepared_headers); -} - void MidiDriver_WIN::close() { - int mode_was = _mode; - _mode = 0; - - switch (mode_was) { - case MO_SIMPLE: - check_error(midiOutClose(_mo)); - break; - case MO_STREAMING:; - check_error(midiStreamStop(_ms)); - check_error(midiOutReset((HMIDIOUT) _ms)); - unprepare(); - check_error(midiStreamClose(_ms)); - break; - } + _isOpen = false; + check_error(midiOutClose(_mo)); } void MidiDriver_WIN::send(uint32 b) @@ -224,9 +76,6 @@ void MidiDriver_WIN::send(uint32 b) BYTE bData[4]; } u; - if (_mode != MO_SIMPLE) - error("MidiDriver_WIN:send called but driver is not in simple mode"); - u.bData[3] = (byte)((b & 0xFF000000) >> 24); u.bData[2] = (byte)((b & 0x00FF0000) >> 16); u.bData[1] = (byte)((b & 0x0000FF00) >> 8); @@ -236,16 +85,6 @@ void MidiDriver_WIN::send(uint32 b) check_error(midiOutShortMsg(_mo, u.dwData)); } -void MidiDriver_WIN::pause(bool p) -{ - if (_mode == MO_STREAMING) { - if (p) - check_error(midiStreamPause(_ms)); - else - check_error(midiStreamRestart(_ms)); - } -} - void MidiDriver_WIN::check_error(MMRESULT result) { char buf[200]; @@ -255,19 +94,6 @@ void MidiDriver_WIN::check_error(MMRESULT result) } } -uint32 MidiDriver_WIN::property(int prop, uint32 param) -{ - switch (prop) { - - // 16-bit time division per the standard MIDI specification - case PROP_TIMEDIV: - _time_div = (uint16)param; - return 1; - } - - return 0; -} - MidiDriver *MidiDriver_WIN_create() { return new MidiDriver_WIN(); |