summaryrefslogtreecommitdiff
path: root/apps/plugins/pdbox/PDa/src/s_midi_sgi.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/pdbox/PDa/src/s_midi_sgi.c')
-rw-r--r--apps/plugins/pdbox/PDa/src/s_midi_sgi.c187
1 files changed, 0 insertions, 187 deletions
diff --git a/apps/plugins/pdbox/PDa/src/s_midi_sgi.c b/apps/plugins/pdbox/PDa/src/s_midi_sgi.c
index cfe8efb0c8..105a812b49 100644
--- a/apps/plugins/pdbox/PDa/src/s_midi_sgi.c
+++ b/apps/plugins/pdbox/PDa/src/s_midi_sgi.c
@@ -186,191 +186,4 @@ void sys_set_priority(int foo)
186 fprintf(stderr, 186 fprintf(stderr,
187 "warning: priority boosting in IRIX not implemented yet\n"); 187 "warning: priority boosting in IRIX not implemented yet\n");
188} 188}
189/* Copyright (c) 1997-1999 Miller Puckette.
190* For information on usage and redistribution, and for a DISCLAIMER OF ALL
191* WARRANTIES, see the file, "LICENSE.txt," in this distribution. */
192
193#include "s_stuff.h"
194#include <stdio.h>
195#include <stdlib.h>
196#include <unistd.h>
197#include <string.h>
198#ifdef HAVE_BSTRING_H
199#include <bstring.h>
200#endif
201#include <sys/types.h>
202#include <sys/time.h>
203
204#include <dmedia/audio.h>
205#include <sys/fpu.h>
206#include <dmedia/midi.h>
207int mdInit(void); /* prototype was messed up in midi.h */
208/* #include "sys/select.h" */
209
210
211 /*
212 set the special "flush zero" but (FS, bit 24) in the
213 Control Status Register of the FPU of R4k and beyond
214 so that the result of any underflowing operation will
215 be clamped to zero, and no exception of any kind will
216 be generated on the CPU.
217
218 thanks to cpirazzi@cp.esd.sgi.com (Chris Pirazzi).
219 */
220
221static void sgi_flush_all_underflows_to_zero(void)
222{
223 union fpc_csr f;
224 f.fc_word = get_fpc_csr();
225 f.fc_struct.flush = 1;
226 set_fpc_csr(f.fc_word);
227}
228
229#define NPORT 2
230
231static MDport sgi_inport[NPORT];
232static MDport sgi_outport[NPORT];
233
234void sgi_open_midi(int midiin, int midiout)
235{
236 int i;
237 int sgi_nports = mdInit();
238 if (sgi_nports < 0) sgi_nports = 0;
239 else if (sgi_nports > NPORT) sgi_nports = NPORT;
240 if (sys_verbose)
241 {
242 if (!sgi_nports)
243 {
244 post("no serial ports are configured for MIDI;");
245 post("if you want to use MIDI, try exiting Pd, typing");
246 post("'startmidi -d /dev/ttyd2' to a shell, and restarting Pd.");
247 }
248 else if (sgi_nports == 1)
249 post("Found one MIDI port on %s", mdGetName(0));
250 else if (sgi_nports == 2)
251 post("Found MIDI ports on %s and %s",
252 mdGetName(0), mdGetName(1));
253 }
254 if (midiin)
255 {
256 for (i = 0; i < sgi_nports; i++)
257 {
258 if (!(sgi_inport[i] = mdOpenInPort(mdGetName(i))))
259 error("MIDI input port %d: open failed", i+1);;
260 }
261 }
262 if (midiout)
263 {
264 for (i = 0; i < sgi_nports; i++)
265 {
266 if (!(sgi_outport[i] = mdOpenOutPort(mdGetName(i))))
267 error("MIDI output port %d: open failed", i+1);;
268 }
269 }
270 return;
271}
272 189
273void sys_putmidimess(int portno, int a, int b, int c)
274{
275 MDevent mdv;
276 if (portno >= NPORT || portno < 0 || !sgi_outport[portno]) return;
277 mdv.msg[0] = a;
278 mdv.msg[1] = b;
279 mdv.msg[2] = c;
280 mdv.msg[3] = 0;
281 mdv.sysexmsg = 0;
282 mdv.stamp = 0;
283 mdv.msglen = 0;
284 if (mdSend(sgi_outport[portno], &mdv, 1) < 0)
285 error("MIDI output error\n");
286 post("msg out %d %d %d", a, b, c);
287}
288
289void sys_putmidibyte(int portno, int foo)
290{
291 error("MIDI raw byte output not available on SGI");
292}
293
294void inmidi_noteon(int portno, int channel, int pitch, int velo);
295void inmidi_controlchange(int portno, int channel, int ctlnumber, int value);
296void inmidi_programchange(int portno, int channel, int value);
297void inmidi_pitchbend(int portno, int channel, int value);
298void inmidi_aftertouch(int portno, int channel, int value);
299void inmidi_polyaftertouch(int portno, int channel, int pitch, int value);
300
301void sys_poll_midi(void)
302{
303 int i;
304 MDport *mp;
305 for (i = 0, mp = sgi_inport; i < NPORT; i++, mp++)
306 {
307 int ret, status, b1, b2, nfds;
308 MDevent mdv;
309 fd_set inports;
310 struct timeval timeout;
311 timeout.tv_sec = 0;
312 timeout.tv_usec = 0;
313 if (!*mp) continue;
314 FD_ZERO(&inports);
315 FD_SET(mdGetFd(*mp), &inports);
316
317 if (select(mdGetFd(*mp)+1 , &inports, 0, 0, &timeout) < 0)
318 perror("midi select");
319 if (FD_ISSET(mdGetFd(*mp),&inports))
320 {
321 if (mdReceive(*mp, &mdv, 1) < 0)
322 error("failure receiving message\n");
323 else if (mdv.msg[0] == MD_SYSEX) mdFree(mdv.sysexmsg);
324
325 else
326 {
327 int status = mdv.msg[0];
328 int channel = (status & 0xf) + 1;
329 int b1 = mdv.msg[1];
330 int b2 = mdv.msg[2];
331 switch(status & 0xf0)
332 {
333 case MD_NOTEOFF:
334 inmidi_noteon(i, channel, b1, 0);
335 break;
336 case MD_NOTEON:
337 inmidi_noteon(i, channel, b1, b2);
338 break;
339 case MD_POLYKEYPRESSURE:
340 inmidi_polyaftertouch(i, channel, b1, b2);
341 break;
342 case MD_CONTROLCHANGE:
343 inmidi_controlchange(i, channel, b1, b2);
344 break;
345 case MD_PITCHBENDCHANGE:
346 inmidi_pitchbend(i, channel, ((b2 << 7) + b1));
347 break;
348 case MD_PROGRAMCHANGE:
349 inmidi_programchange(i, channel, b1);
350 break;
351 case MD_CHANNELPRESSURE:
352 inmidi_aftertouch(i, channel, b1);
353 break;
354 }
355 }
356 }
357 }
358}
359
360void sys_open_midi(int nmidiin, int *midiinvec,
361 int nmidiout, int *midioutvec)
362{
363 sgi_open_midi(nmidiin!=0, nmidiout!=0);
364}
365
366
367void sys_close_midi( void)
368{
369 /* ??? */
370}
371
372void sys_set_priority(int foo)
373{
374 fprintf(stderr,
375 "warning: priority boosting in IRIX not implemented yet\n");
376}