Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Device list never changes #4

Closed
jimm opened this issue Jun 12, 2016 · 5 comments
Closed

Device list never changes #4

jimm opened this issue Jun 12, 2016 · 5 comments

Comments

@jimm
Copy link

jimm commented Jun 12, 2016

PortMidi.devices never changes its return value while the app is running. If I attach/detach new MIDI devices or open MIDI apps that open MIDI input/output ports, calling PortMidi.devices does not reflect the new list of available devices.

@jimm
Copy link
Author

jimm commented Jun 14, 2016

Portmidi itself doesn't do this. I wrote a simple test program in C and verified that if I get all the devices periodically, the list does not change even when I detach MIDI devices/apps. I've copied the test program below in case anybody is interested.

I'm closing this ticket.

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include "portmidi.h"

void list(const char *title, const PmDeviceInfo *infos[], int num_devices) {
  printf("%s:\n", title);
  for (int i = 0; i < num_devices; ++i)
    if (infos[i] != 0)
      printf("  %s%s\n", infos[i]->name, infos[i]->opened ? " (open)" : "");
}

void list_all_devices() {
  int num_devices = Pm_CountDevices();
  const PmDeviceInfo *inputs[num_devices], *outputs[num_devices];

  for (int i = 0; i < num_devices; ++i) {
    const PmDeviceInfo *info = Pm_GetDeviceInfo(i);
    inputs[i] = info->input ? info : 0;
    outputs[i] = info->output ? info : 0;
  }

  list("Inputs", inputs, num_devices);
  list("Outputs", outputs, num_devices);
}

int main(int argc, char **argv) {
  for (;;) {
    printf("\n\n\n");
    list_all_devices();
    sleep(5);
  }
  exit(0);
}

@jimm jimm closed this as completed Jun 14, 2016
@lucidstack
Copy link
Owner

Hi @jimm, thanks for pointing that out. I was having a look at this, and couldn't find any caching points, or similar issues. I might look into the Portmidi source code, to see if there is any way to refresh that list.

@jimm
Copy link
Author

jimm commented Jun 16, 2016

Calling Pm_Terminate and Pm_Initialize is part of the solution. The list will be updated, but the device count remains the same. I just tried running this C code:

  for (int i = 0; i < 5; ++i) {
    printf("\n\n\n");
    Pm_Initialize();
    list_all_devices();
    Pm_Terminate();
    sleep(5);
  }

Here is the output, as I quit removed first SimpleSynth then MidiPipe:

Inputs:
   0: IAC Driver Bus 1
   1: MidiPipe Output 1
Outputs:
   2: IAC Driver Bus 1
   3: MidiPipe Input 1
   4: SimpleSynth virtual input



Inputs:
   0: IAC Driver Bus 1
   1: MidiPipe Output 1
Outputs:
   2: IAC Driver Bus 1
   3: MidiPipe Input 1
   4: SimpleSynth virtual input



Inputs:
   0: IAC Driver Bus 1
   1: MidiPipe Output 1
Outputs:
   2: IAC Driver Bus 1
   3: MidiPipe Input 1
   4:



Inputs:
   0: IAC Driver Bus 1
   1:
Outputs:
   2: IAC Driver Bus 1
   3:
   4:



Inputs:
Outputs:

So it looks like the count was updated the last time for some reason.

Looking briefly at the portmidi code, it looks like the global pm_descriptor_index never gets reset to 0 in the code. I wonder if your C interface code could do that before calling Pm_Initialize.

Also, when I added the MIDI apps back during a run, the count never got higher so I didn't see the newly added MIDI ports. I don't have time to poke around any more right now.

@thbar
Copy link
Collaborator

thbar commented Jun 22, 2019

I had the same issue today, especially relevant while working with LiveView + PortMIDI (see slides of a talk I gave recently for more context).

If any of you found a proper work-around for this, I'm interested!

@thbar
Copy link
Collaborator

thbar commented Jun 22, 2019

From the PortMidi doc, sadly:

Note that MIDI devices added after the Portmidi library has been initializd will not be reflected in the list of descriptions.

http:https://www.moz.ac.at/sem/lehre/lib/cm/CM.app/Contents/Resources/cm/doc/dict/portmidi-topic.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants