annotate c/portmidi/main.cc @ 31:4580f792d4c6

portmidi test program
author Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
date Tue, 05 Aug 2014 15:02:54 +0900
parents
children d6fd8aaaa358
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 #include <iostream>
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 #include "portmidi.h"
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 #include "porttime.h"
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 #include <time.h>
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 #include <stdlib.h>
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
6
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 #define TIME_PROC ((long (*)(void *)) Pt_Time)
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 using namespace std;
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
10
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
11 PmStream * midi;
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 char line[80];
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
13 PmEvent buffer[5];
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 void process_midi(PtTimestamp timestamp, void *userData);
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
15
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 int main(int argc, char *argv[])
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
17 {
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 //pt_start must be called before initialising midi
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 Pt_Start(2000, &process_midi, 0);
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 Pm_Initialize();
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 int device = 0;//microsoft midi mapper...
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 Pm_OpenOutput(&midi,device,NULL,0,NULL,NULL,10);
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 /*calling callback function once. When I called Pt_start
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 it waits until 'resolution' millisecs have passed before
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 start, hence I call the callback function once beforehand */
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 process_midi(0, NULL);
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 cin.get();
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 //wiat for user input and then stop midi timer callback function...
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 Pt_Stop();
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 Pm_Close(midi);
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 printf("done closing and terminating...\n");
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 Pm_Terminate();
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 }
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
34
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 void process_midi(PtTimestamp timestamp, void *userData)
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 {
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
37 buffer[0].timestamp = timestamp+0;
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 buffer[0].message = Pm_Message(0x90, 60, 100);
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 buffer[1].timestamp = timestamp+1000;
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 buffer[1].message = Pm_Message(0x90, 60, 0);
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 buffer[2].timestamp = timestamp+1000;
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 buffer[2].message = Pm_Message(0x90, 64, 100);
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 buffer[3].timestamp = timestamp+2000;
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
44 buffer[3].message = Pm_Message(0x90, 64, 0);
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 Pm_Write(midi, buffer, 4);
4580f792d4c6 portmidi test program
Masataka Kohagura <kohagura@cr.ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 }