From 9c0e19a3be2288db79e2502e5fa450c3e20a668d Mon Sep 17 00:00:00 2001 From: Guenter Geiger Date: Fri, 9 May 2003 16:04:00 +0000 Subject: This commit was generated by cvs2svn to compensate for changes in r610, which included commits to RCS files with non-trunk default branches. svn path=/trunk/; revision=611 --- pd/portmidi_osx/pmtest.c | 136 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 136 insertions(+) create mode 100644 pd/portmidi_osx/pmtest.c (limited to 'pd/portmidi_osx/pmtest.c') diff --git a/pd/portmidi_osx/pmtest.c b/pd/portmidi_osx/pmtest.c new file mode 100644 index 00000000..5628d25e --- /dev/null +++ b/pd/portmidi_osx/pmtest.c @@ -0,0 +1,136 @@ +#include +#include +#include + +#include "portmidi.h" +#include "porttime.h" +#include "pminternal.h" + +#define LATENCY 0 +#define NUM_ECHOES 10 + +int +main() +{ + int i = 0; + int n = 0; + PmStream *midi_in; + PmStream *midi_out; + PmError err; + char line[80]; + PmEvent buffer[NUM_ECHOES]; + int transpose; + int delay; + int status, data1, data2; + int statusprefix; + + + + /* always start the timer before you start midi */ + Pt_Start(1, 0, 0); /* start a timer with millisecond accuracy */ + + + for (i = 0; i < Pm_CountDevices(); i++) { + const PmDeviceInfo *info = Pm_GetDeviceInfo(i); + printf("%d: %s, %s", i, info->interf, info->name); + if (info->input) printf(" (input)"); + if (info->output) printf(" (output)"); + printf("\n"); + } + + /* OPEN INPUT DEVICE */ + + printf("Type input number: "); + while (n != 1) { + n = scanf("%d", &i); + gets(line); + } + + err = Pm_OpenInput(&midi_in, i, NULL, 100, NULL, NULL, NULL); + if (err) { + printf("could not open midi device: %s\n", Pm_GetErrorText(err)); + exit(1); + } + printf("Midi Input opened.\n"); + + /* OPEN OUTPUT DEVICE */ + + printf("Type output number: "); + n = 0; + while (n != 1) { + n = scanf("%d", &i); + gets(line); + } + + err = Pm_OpenOutput(&midi_out, i, NULL, 0, NULL, NULL, LATENCY); + if (err) { + printf("could not open midi device: %s\n", Pm_GetErrorText(err)); + exit(1); + } + printf("Midi Output opened with %d ms latency.\n", LATENCY); + + + + /* Get input from user for parameters */ + printf("Type number of milliseconds for echoes: "); + n = 0; + while (n != 1) { + n = scanf("%d", &delay); + gets(line); + } + + printf("Type number of semitones to transpose up: "); + n = 0; + while (n != 1) { + n = scanf("%d", &transpose); + gets(line); + } + + + + /* loop, echoing input back transposed with multiple taps */ + + printf("Press C2 on the keyboard (2 octaves below middle C) to quit.\nWaiting for MIDI input...\n"); + + do { + err = Pm_Read(midi_in, buffer, 1); + if (err == 0) continue; /* no bytes read. */ + + /* print a hash mark for each event read. */ + printf("#"); + fflush(stdout); + + status = Pm_MessageStatus(buffer[0].message); + data1 = Pm_MessageData1(buffer[0].message); + data2 = Pm_MessageData2(buffer[0].message); + statusprefix = status >> 4; + + /* ignore messages other than key-down and key-up */ + if ((statusprefix != 0x9) && (statusprefix != 0x8)) continue; + + printf("\nReceived key message = %X %X %X, at time %ld\n", status, data1, data2, buffer[0].timestamp); + fflush(stdout); + + /* immediately send the echoes to PortMIDI */ + for (i = 1; i < NUM_ECHOES; i++) { + buffer[i].message = Pm_Message(status, data1 + transpose, data2 >> i); + buffer[i].timestamp = buffer[0].timestamp + (i * delay); + } + Pm_Write(midi_out, buffer, NUM_ECHOES); + } while (data1 != 36); /* quit when C2 is pressed */ + + printf("Key C2 pressed. Exiting...\n"); + fflush(stdout); + + /* Give the echoes time to finish before quitting. */ + sleep(((NUM_ECHOES * delay) / 1000) + 1); + + Pm_Close(midi_in); + Pm_Close(midi_out); + + printf("Done.\n"); + return 0; +} + + + -- cgit v1.2.1