Ticket #175: linux_mid

File linux_mid, 4.0 KB (added by SF/fatpenguin, 18 years ago)

Linux midi sequencer patch

Line 
1Index: gameDetector.cpp
2===================================================================
3RCS file: /cvsroot/scummvm/scummvm/gameDetector.cpp,v
4retrieving revision 1.24
5diff -u -3 -p -r1.24 gameDetector.cpp
6--- gameDetector.cpp 19 Apr 2002 15:02:14 -0000 1.24
7+++ gameDetector.cpp 20 Apr 2002 11:20:22 -0000
8@@ -455,6 +455,7 @@ MidiDriver *GameDetector::createMidi() {
9 #ifdef __MORPHOS__
10 case MD_AMIDI: return MidiDriver_AMIDI_create();
11 #endif
12+ case MD_SEQ: return MidiDriver_SEQ_create();
13 }
14
15 error("Invalid midi driver selected");
16Index: sound/mididrv.cpp
17===================================================================
18RCS file: /cvsroot/scummvm/scummvm/sound/mididrv.cpp,v
19retrieving revision 1.5
20diff -u -3 -p -r1.5 mididrv.cpp
21--- sound/mididrv.cpp 18 Apr 2002 21:40:24 -0000 1.5
22+++ sound/mididrv.cpp 20 Apr 2002 11:20:24 -0000
23@@ -347,6 +347,137 @@ MidiDriver *MidiDriver_AMIDI_create() {
24
25 #endif // __MORPHOS__
26
27+#define SEQ_MIDIPUTC 5
28+#define SPECIAL_CHANNEL 9
29+#define DEVICE_NUM 1
30+
31+class MidiDriver_SEQ : public MidiDriver {
32+public:
33+ MidiDriver_SEQ();
34+ void destroy();
35+ int open(int mode);
36+ void close();
37+ void send(uint32 b);
38+ void pause(bool pause);
39+ void set_stream_callback(void *param, StreamCallback *sc);
40+
41+private:
42+ StreamCallback *_stream_proc;
43+ void *_stream_param;
44+ int _mode;
45+ uint16 _time_div;
46+ int device;
47+ uint32 property(int prop, uint32 param);
48+};
49+
50+MidiDriver_SEQ::MidiDriver_SEQ(){
51+ _mode=0;
52+ device=0;
53+}
54+
55+int MidiDriver_SEQ::open(int mode) {
56+ if (_mode != 0)
57+ return MERR_ALREADY_OPEN;
58+ device = 0;
59+ _mode=mode;
60+ if (mode!=MO_SIMPLE) return MERR_STREAMING_NOT_AVAILABLE;
61+#if !defined(__APPLE__CW) // No getenv support on Apple Carbon
62+ char *device_name = getenv("SCUMMVM_MIDI");
63+ if (device_name != NULL) {
64+ device = (::open((device_name), O_RDWR, 0));
65+ } else {
66+ warning("You need to set-up the SCUMMVM_MIDI environment variable properly (see readme.txt) ");
67+ }
68+ if ((device_name == NULL) || (device < 0)) {
69+ if (device_name == NULL)
70+ warning("Opening /dev/null (no music will be heard) ");
71+ else
72+ warning("Cannot open rawmidi device %s - using /dev/null (no music will be heard) ", device_name);
73+ device = (::open(("/dev/null"), O_RDWR, 0));
74+ if (device < 0)
75+ error("Cannot open /dev/null to dump midi output");
76+ }
77+#endif
78+ return 0;
79+}
80+
81+void MidiDriver_SEQ::close() {
82+ ::close(device);
83+ _mode = 0;
84+}
85+
86+
87+void MidiDriver_SEQ::send(uint32 b)
88+{
89+ unsigned char buf[256];
90+ int position = 0;
91+
92+ switch (b & 0xF0) {
93+ case 0x80:
94+ case 0x90:
95+ case 0xA0:
96+ case 0xB0:
97+ case 0xE0:
98+ buf[position++] = SEQ_MIDIPUTC;
99+ buf[position++] = b;
100+ buf[position++] = DEVICE_NUM;
101+ buf[position++] = 0;
102+ buf[position++] = SEQ_MIDIPUTC;
103+ buf[position++] = (b >> 8) & 0x7F;
104+ buf[position++] = DEVICE_NUM;
105+ buf[position++] = 0;
106+ buf[position++] = SEQ_MIDIPUTC;
107+ buf[position++] = (b >> 16) & 0x7F;
108+ buf[position++] = DEVICE_NUM;
109+ buf[position++] = 0;
110+ break;
111+ case 0xC0:
112+ case 0xD0:
113+ buf[position++] = SEQ_MIDIPUTC;
114+ buf[position++] = b;
115+ buf[position++] = DEVICE_NUM;
116+ buf[position++] = 0;
117+ buf[position++] = SEQ_MIDIPUTC;
118+ buf[position++] = (b >> 8) & 0x7F;
119+ buf[position++] = DEVICE_NUM;
120+ buf[position++] = 0;
121+ break;
122+ default:
123+ fprintf(stderr, "Unknown : %08x\n", b);
124+ break;
125+ }
126+ write(device, buf, position);
127+}
128+
129+void MidiDriver_SEQ::pause(bool pause) {
130+ if (_mode == MO_STREAMING) {
131+ }
132+}
133+
134+void MidiDriver_SEQ::set_stream_callback(void *param, StreamCallback *sc) {
135+ _stream_param = param;
136+ _stream_proc = sc;
137+}
138+
139+MidiDriver *MidiDriver_SEQ_create() {
140+ return new MidiDriver_SEQ();
141+}
142+
143+void MidiDriver_SEQ::destroy() {
144+ close();
145+ delete this;
146+}
147+
148+uint32 MidiDriver_SEQ::property(int prop, uint32 param) {
149+ switch(prop) {
150+ /* 16-bit time division according to standard midi specification */
151+ case PROP_TIMEDIV:
152+ _time_div = (uint16)param;
153+ return 1;
154+ }
155+
156+ return 0;
157+}
158
159 /* NULL driver */
160 class MidiDriver_NULL : public MidiDriver {