porttest.c
1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <miditime.h>
#include <midi.h>
#include <midiio.h>
MIport *MInewport(void);
MIconfig *MInewconfig(void);
main()
{
MIport *port;
MIconfig *c;
MIevent e;
register int i;
int channel = 0;
printf("Sending on MIDI channel %d\n", channel+1);
c = MInewconfig();
MICsetstamp(c, MIDELTASTAMP);
port = MInewport();
if (MIopen(port, "w", c) < 0) {
perror("open");
exit(-1);
}
MImakemessage(&e.mm.msgbuf, MIDI_NoteOn, channel, 0, 0);
for (i = 48; i <= 60; i++)
{
MItime zero;
MItime half;
zero = MItimecreatemicros(0);
half = MItimecreatemicros(500000);
MIsetbyte1(&e.mm.msgbuf, i);
MIsetbyte2(&e.mm.msgbuf, 0x60);
e.dt = zero;
e.t = MIMESSAGE;
if (MIsend(port, &e, 1) < 0)
{
perror("send note on");
exit(-1);
}
MIsetbyte1(&e.mm.msgbuf, i);
MIsetbyte2(&e.mm.msgbuf, 0x0);
e.dt = half;
e.t = MIMESSAGE;
if (MIsend(port, &e, 1) < 0)
{
perror("send note off");
exit(-1);
}
}
sleep(5);
}