]> git.rkrishnan.org Git - pihpsdr.git/commitdiff
Corrections mainly for Linux/MIDI
authorc vw <dl1ycf@darc.de>
Fri, 14 May 2021 13:18:01 +0000 (15:18 +0200)
committerc vw <dl1ycf@darc.de>
Fri, 14 May 2021 13:18:01 +0000 (15:18 +0200)
alsa_midi.c
mac_midi.c
radio.c

index c7ae59af03d3073d5b4b6988574a7d73d678a35b..d05ad69176128ac5202fd56f68b7a5564fbd8a90 100644 (file)
@@ -96,7 +96,6 @@ static void *midi_thread(void *arg) {
         if (!(revents & POLLIN)) continue;
        // something has arrived
        ret = snd_rawmidi_read(input, buf, 64);
-       g_print("%s: raw read returned %d\n", __FUNCTION__,ret);
         if (ret == 0) continue;
         if (ret < 0) {
             fprintf(stderr,"cannot read from port \"%s\": %s\n", port, snd_strerror(ret));
@@ -205,7 +204,7 @@ void register_midi_device(int index) {
     snd_rawmidi_read(midi_input[index], NULL, 0); /* trigger reading */
 
 
-    ret = pthread_create(&midi_thead_id[index], NULL, midi_thread, (void *) index);
+    ret = pthread_create(&midi_thread_id[index], NULL, midi_thread, (void *) index);
     if (ret < 0) {
       g_print("%s: Failed to create MIDI read thread\n",__FUNCTION__);
       if((ret = snd_rawmidi_close(midi_input[index])) < 0) {
@@ -233,7 +232,7 @@ void close_midi_device(int index) {
   //
   // wait for thread to complete
   //
-  ret=pthread_join(midi_devices[index].midi_thread_id, NULL);
+  ret=pthread_join(midi_thread_id[index], NULL);
   if (ret  != 0)  {
     g_print("%s: cannot join: %s\n", __FUNCTION__, strerror(ret));
   }     
@@ -309,7 +308,6 @@ void get_midi_devices() {
                     sprintf(portname,"hw:%d,%d,%d", card, device, sub);
                     devnam=subnam;
                 }
-
                 //
                 // If the name was already present at the same position, just keep
                 // it and do nothing.
@@ -319,21 +317,25 @@ void get_midi_devices() {
                 int match = 1;
                 if (midi_devices[n_midi_devices].name == NULL) {
                   midi_devices[n_midi_devices].name=g_new(gchar,strlen(devnam)+1);
+                 strcpy(midi_devices[n_midi_devices].name, devnam);
                   match = 0;
                 } else {
-                  if (strcmp(devnam, midi_devices[n_midi_devices].name) {
+                  if (strcmp(devnam, midi_devices[n_midi_devices].name)) {
                     g_free(midi_devices[n_midi_devices].name);
                     midi_devices[n_midi_devices].name=g_new(gchar,strlen(devnam)+1);
+                   strcpy(midi_devices[n_midi_devices].name, devnam);
                     match = 0;
                   }
                 }
                 if (midi_port[n_midi_devices] == NULL) {
                   midi_port[n_midi_devices]=g_new(gchar,strlen(portname)+1);
+                 strcpy(midi_port[n_midi_devices], portname);
                   match = 0;
                 } else {
-                  if (strcmp(midi_port[n_midi_devices], portname) {
+                  if (strcmp(midi_port[n_midi_devices], portname)) {
                     g_free(midi_port[n_midi_devices]);
                     midi_port[n_midi_devices]=g_new(gchar,strlen(portname)+1);
+                   strcpy(midi_port[n_midi_devices], portname);
                     match = 0;
                   }
                 }
@@ -342,7 +344,7 @@ void get_midi_devices() {
                 // the same as before. In this case, just let the thread
                 // proceed
                 //
-                if (match == 0 && midi_index[n_midi_devices].active) {
+                if (match == 0 && midi_devices[n_midi_devices].active) {
                   close_midi_device(n_midi_devices);
                 }
                 n_midi_devices++;
@@ -357,7 +359,7 @@ void get_midi_devices() {
     }
 
     for(int i=0;i<n_midi_devices;i++) {
-        g_print("%s: %d: %s %s\n",__FUNCTION__,i,midi_devices[i].name,midi_devices[i].port);
+        g_print("%s: %d: %s %s\n",__FUNCTION__,i,midi_devices[i].name,midi_port[i]);
     }
 }
 #endif
index e126a158505a90a1cdc60d3ad3d819e40d45526c..5336e66ea9610b5a87648ac6241fbbc57955c7ee 100644 (file)
@@ -197,14 +197,14 @@ void close_midi_device(index) {
     midi_devices[index].active=0;
 }
 
-int register_midi_device(int index) {
+void register_midi_device(int index) {
     OSStatus osret;
 
     g_print("%s: index=%d\n",__FUNCTION__,index);
 //
 //  Register a callback routine for the device
 //
-    if (index < 0 || index > MAX_MIDI_DEVICES) return -1;
+    if (index < 0 || index > MAX_MIDI_DEVICES) return;
 
      myClients[index]=0;
      myMIDIports[index] = 0;
@@ -212,23 +212,23 @@ int register_midi_device(int index) {
      osret=MIDIClientCreate(CFSTR("piHPSDR"),NULL,NULL, &myClients[index]);
      if (osret !=0) {
        g_print("%s: MIDIClientCreate failed with ret=%d\n", __FUNCTION__, (int) osret);
-       return -1;
+       return;
      }
      osret=MIDIInputPortCreate(myClients[index], CFSTR("FromMIDI"), ReadMIDIdevice, NULL, &myMIDIports[index]);
      if (osret !=0) {
         g_print("%s: MIDIInputPortCreate failed with ret=%d\n", __FUNCTION__, (int) osret);
-        return -1;
+        return;
      }
      osret=MIDIPortConnectSource(myMIDIports[index] ,MIDIGetSource(index), NULL);
      if (osret != 0) {
         g_print("%s: MIDIPortConnectSource failed with ret=%d\n", __FUNCTION__, (int) osret);
-        return -1;
+        return;
      }
      //
      // Now we have successfully opened the device.
      //
      midi_devices[index].active=1;
-     return 0;
+     return;
 }
 
 void get_midi_devices() {
diff --git a/radio.c b/radio.c
index 272372a9f25cdec999ffb55ab031c20dd281bd38..a217fc434d705101cce25b5ffe3efd43c894207e 100644 (file)
--- a/radio.c
+++ b/radio.c
@@ -1307,12 +1307,11 @@ void start_radio() {
     if (midi_devices[i].active) {
       //
       // If device was marked "active" in the props file, open (register) it
+      // Note this flag is hi-jacked, so clear it before opening. It will be set
+      // if the MIDI device has been opened successfully
       //
-      if (register_midi_device(i) == 0) {
-        g_print("%s: MIDI device %s (index=%d) registered\n", __FUNCTION__, midi_devices[i].name, i);
-      } else {
-        g_print("%s: MIDI device %s (index=%d) could not be opened\n", __FUNCTION__, midi_devices[i].name, i);
-      }
+      midi_devices[i].active=0;
+      register_midi_device(i);
     }
   }
 #endif