summaryrefslogtreecommitdiffstats
path: root/src/midi.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/midi.c')
-rw-r--r--src/midi.c57
1 files changed, 54 insertions, 3 deletions
diff --git a/src/midi.c b/src/midi.c
index 389a670..5a556e9 100644
--- a/src/midi.c
+++ b/src/midi.c
@@ -46,6 +46,7 @@ void midi_decode(uint32_t msg, synth_t * synth) {
case 0x0B:
printf("Control Change: channel=%d, controller=%d, value=%d\n", channel, data1, data2);
int x = data2 < 64 ? 1 : -1;
+ int val;
switch (data1) {
case 0:
cc_step(&synth->cc_adsr_a, x);
@@ -94,6 +95,7 @@ void midi_decode(uint32_t msg, synth_t * synth) {
if (synth->geni < 6) synth->geni++;
break;
default:
+ break;
}
break;
case 0x0C:
@@ -103,7 +105,7 @@ void midi_decode(uint32_t msg, synth_t * synth) {
printf("Channel Pressure: channel=%d, pressure=%d\n", channel, data1);
break;
case 0x0E:
- int val = ((data2 << 7) | data1) - 8192;
+ val = ((data2 << 7) | data1) - 8192;
printf("Pitch Bend: channel=%d, value=%d\n", channel, val);
float pitch;
float semitones = 2;
@@ -126,6 +128,7 @@ void midi_decode(uint32_t msg, synth_t * synth) {
int enable = 0;
void
midiCallback(PtTimestamp timestamp, void *userData) {
+ (void)timestamp;
midi_t * m = (midi_t *)userData;
if (!m->stream) return;
@@ -156,12 +159,19 @@ init_midi(midi_t *m, synth_t *synth)
printf("midi devs: %d\n", Pm_CountDevices());
const PmDeviceInfo *info;
- int i;
+ int i, c=0;
for (i = 0; i < Pm_CountDevices(); i++) {
info = Pm_GetDeviceInfo(i);
+ if (!info->input) {
+ continue;
+ }
printf("%d: %s [input: %d output: %d opened: %d is_virt:%d] (interf: %s) -- %d\n", i, info->name, info->input, info->output, info->opened, info->is_virtual, info->interf, Pm_GetDefaultInputDeviceID());
+ if (synth->midi_device_id == c) {
+ break;
+ }
+ c++;
//if (!strcmp("MPK225 MIDI", info->name) && !info->input) break;
- if (!strcmp("MPK225 Port A", info->name) && info->input == 1) break;
+ //if (!strcmp("MPK225 Port A", info->name) && info->input == 1) break;
//if (!strcmp("CH345 MIDI 1", info->name) && info->input == 1) break;
//if (!strcmp("Midi Through Port-0", info->name) && info->input == 1) break;
//if (!strcmp("DigitalKBD MIDI 1", info->name) && info->input == 1) break;
@@ -178,6 +188,47 @@ init_midi(midi_t *m, synth_t *synth)
enable = 1;
}
+int
+get_midi_device_id(const char * name)
+{
+ int i, c=0;
+ const PmDeviceInfo *info;
+ for (i = 0; i < Pm_CountDevices(); i++) {
+ info = Pm_GetDeviceInfo(i);
+ if (!info->input) {
+ continue;
+ }
+ if (!strcmp(name, info->name)) {
+ return c;
+ }
+ c++;
+ }
+ return -1;
+}
+
+char *
+get_midi_devices()
+{
+ //Pm_Initialize();
+ int i;
+ char *ret = (char *)malloc(sizeof(char) * 4096);
+ strcpy(ret, "");
+ const PmDeviceInfo *info;
+ for (i = 0; i < Pm_CountDevices(); i++) {
+ info = Pm_GetDeviceInfo(i);
+ if (!info->input) {
+ continue;
+ }
+ printf("!!!!!!!!!!!!!!!!!!!!!!!!! ==> %s ========\n", info->name);
+ strcat(ret, info->name);
+ strcat(ret, ";");
+ }
+ ret[strlen(ret) - 1] = '\0';
+ //Pm_Terminate();
+
+ return ret;
+}
+
void
terminate_midi(midi_t *m)
{