3 Ann Hell Ex Machina - Music Software
4 Copyright (C) 2003/2005 Angel Ortega <angel@triptico.com>
6 midiin.c - Code for testing the libraries
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 http://www.triptico.com
32 #include <sys/types.h>
38 #include "ss_output.h"
47 #define MIDI_NOTE_OFF 0x80
48 #define MIDI_NOTE_ON 0x90
49 #define MIDI_AFTERTOUCH 0xA0
50 #define MIDI_PARAMETER 0xB0
51 #define MIDI_PROGRAM 0xC0
52 #define MIDI_PRESSURE 0xD0
53 #define MIDI_PITCHWHEEL 0xE0
54 #define MIDI_SYSEX 0xF0
58 char _midi_dev
[150]="/dev/midi";
62 char _pat_instrument
[150]="samples/acpiano.pat";
67 /* the MIDI message */
68 unsigned char midimsg
[128];
75 void process_MIDI(void)
77 /* strip MIDI channel */
80 if(midimsg
[0] == MIDI_NOTE_OFF
)
81 ss_ins_note_off(&i
, midimsg
[1]);
83 if(midimsg
[0] == MIDI_NOTE_ON
)
84 ss_ins_note_on(&i
, midimsg
[1],
85 ((float)midimsg
[2]) / 127.0, midimsg
[1]);
93 unsigned char midibuf
[128];
99 /* read from MIDI device */
100 c
=read(_midi_fd
, midibuf
, sizeof(midibuf
));
106 /* if 7bit of input is set,
107 it's a start of MIDI message */
108 if((midibuf
[n
] & 0x80) && i_msg
)
111 midimsg
[i_msg
++]=midibuf
[n
];
115 ss_output_init_frame(sample
);
116 ss_ins_frame(&i
, sample
);
117 ss_output_write(sample
);
122 int main(int argc
, char * argv
[])
132 printf("midiin [instrument.pat] [midi device]\n");
137 strcpy(_pat_instrument
, argv
[1]);
140 strcpy(_midi_dev
, argv
[2]);
142 /* loads the instrument or bangs */
144 if(ss_load_pat_file(&i
, _pat_instrument
) < 0)
146 printf("Error loading '%s'\n", _pat_instrument
);
150 /* opens the ahxm output driver */
151 if(ss_output_open("default", NULL
) < 0)
153 printf("Error opening ahxm output driver\n");
157 /* opens the MIDI channel */
158 if((_midi_fd
=open(_midi_dev
, O_RDONLY
|O_NONBLOCK
))==-1)
160 printf("Error opening midi device '%s'\n", _midi_dev
);