int keyboard_init(MidiObj* m,char* name) { m->midi_stream_out = NULL; m->midi_stream = NULL; // open midi device if(! initialized) { Pm_Initialize(); initialized=1; } int devid= find_device_id_in(name); int devid_out= find_device_id_out(name); const PmDeviceInfo* dev_info = Pm_GetDeviceInfo(devid); const PmDeviceInfo* dev_info_out = Pm_GetDeviceInfo(devid_out); if(dev_info_out) { Pm_OpenOutput(&(m->midi_stream_out), devid_out, NULL, KEYBOARD_MAX_EVENTS, NULL, NULL,0); } if(dev_info) { Pm_OpenInput(&(m->midi_stream), devid, NULL, KEYBOARD_MAX_EVENTS, NULL, NULL); return 1; } return 0; }
void pm_module::list_midi_devices(void) { int num_devs = Pm_CountDevices(); const PmDeviceInfo *pmInfo; printf("\n"); if (num_devs == 0) { printf("No MIDI ports were found\n"); return; } printf("MIDI input ports:\n"); for (int i = 0; i < num_devs; i++) { pmInfo = Pm_GetDeviceInfo(i); if (pmInfo->input) { printf("%s %s\n", pmInfo->name, (i == Pm_GetDefaultInputDeviceID()) ? "(default)" : ""); } } printf("\nMIDI output ports:\n"); for (int i = 0; i < num_devs; i++) { pmInfo = Pm_GetDeviceInfo(i); if (pmInfo->output) { printf("%s %s\n", pmInfo->name, (i == Pm_GetDefaultOutputDeviceID()) ? "(default)" : ""); } } }
void FLiveEditorManager::FindDevices() { //find all our devices int NumDevices = Pm_CountDevices(); //needs to remain int (instead of int32) since numbers are derived from TPL that uses int for ( int i = 0; i < NumDevices; i++ ) { const PmDeviceInfo *Info = Pm_GetDeviceInfo( i ); if ( Info->input && !InputConnections.Find(i) ) { PortMidiStream *MIDIStream; PmError Error = Pm_OpenInput( &MIDIStream, i, NULL, DEFAULT_BUFFER_SIZE, NULL, NULL ); if ( Error == pmNoError ) { FLiveEditorDeviceInstance DeviceInstance; DeviceInstance.Data.DeviceName = FString(Info->name); DeviceInstance.Connection.MIDIStream = MIDIStream; LoadDeviceData( DeviceInstance.Data.DeviceName, DeviceInstance.Data ); InputConnections.Add( i, DeviceInstance ); } } } }
/* * Method: Pm_GetDeviceName */ JNIEXPORT jstring JNICALL Java_jportmidi_JPortMidiApi_Pm_1GetDeviceName (JNIEnv *env, jclass cl, jint i) { const PmDeviceInfo *info = Pm_GetDeviceInfo(i); if (!info) return NULL; return (*env)->NewStringUTF(env, info->name); }
void MidiSession::openOutputDevice(std::string device) { auto numMidiInputs = Pm_CountDevices(); auto devices = getDevices(); for(auto i = 0; i < numMidiInputs; i++) { if(devices[i] == device) { if(!Pm_GetDeviceInfo(i)->opened) error = Pm_OpenOutput(&midiStream, i, nullptr, 3, nullptr, nullptr, 0); else std::cout<<"Device is already opened"<<std::endl; if(error != pmNoError) { std::cout<<"Trying to open device: "<<devices[i]<<std::endl; std::cout<<Pm_GetErrorText(error)<<std::endl; return; } midiThread = std::thread(&MidiSession::read, this); midiThread.detach(); return; } } }
/* utility to look up device, given a pattern, note: pattern is modified */ int pm_find_default_device(char *pattern, int is_input) { int id = pmNoDevice; int i; /* first parse pattern into name, interf parts */ char *interf_pref = ""; /* initially assume it is not there */ char *name_pref = strstr(pattern, ", "); if (name_pref) { /* found separator, adjust the pointer */ interf_pref = pattern; name_pref[0] = 0; name_pref += 2; } else { name_pref = pattern; /* whole string is the name pattern */ } for (i = 0; i < pm_descriptor_index; i++) { const PmDeviceInfo *info = Pm_GetDeviceInfo(i); if (info->input == is_input && strstr(info->name, name_pref) && strstr(info->interf, interf_pref)) { id = i; break; } } return id; }
bool midiInit() { Pm_Initialize(); // Initialize buffer nbEventWaiting = 0; iEventWaiting = 0; int portIn = -1; int portOut = -1; /* List device information */ for (int i = 0; i < Pm_CountDevices(); i++) { const PmDeviceInfo *info = Pm_GetDeviceInfo(i); if ((info->input) || (info->output)) { printf("%d: %s, %s", i, info->interf, info->name); if (info->input) { portIn = i; printf(" (input)"); } if (info->output) { portOut = i; printf(" (output)"); } printf("\n"); } } if(portOut == -1 || portIn == -1) { printf("Midi port not found.\r\n"); return -1; } return false; }
/* * Method: Pm_GetDeviceOutput */ JNIEXPORT jboolean JNICALL Java_jportmidi_JPortMidiApi_Pm_1GetDeviceOutput (JNIEnv *env, jclass cl, jint i) { const PmDeviceInfo *info = Pm_GetDeviceInfo(i); if (!info) return (jboolean) 0; return (jboolean) info->output; }
int main(int argc, char **argv) { int argi, i; char *arg, *nextarg; PmError perr; PtError pterr; PmDeviceID dev = -1; int list = 0; for (argi = 1; argi < argc; argi++) { arg = argv[argi]; nextarg = argv[argi+1]; if (arg[0] == '-') { if (!strcmp(arg, "-l")) { list = 1; } else if (!strcmp(arg, "-i") && nextarg) { dev = atoi(nextarg); argi++; } else { fprintf(stderr, "Invalid invocation.\n"); exit(1); } } } PSF(perr, Pm_Initialize, ()); PTSF(pterr, Pt_Start, (1, dump, NULL)); /* list devices */ if (list) { int ct = Pm_CountDevices(); PmDeviceID def = Pm_GetDefaultInputDeviceID(); const PmDeviceInfo *devinf; for (i = 0; i < ct; i++) { devinf = Pm_GetDeviceInfo(i); printf("%d%s: %s%s %s\n", i, (def == i) ? "*" : "", (devinf->input) ? "I" : "", (devinf->output) ? "O" : "", devinf->name); } } /* choose device */ if (dev == -1) { fprintf(stderr, "Warning: Using default device.\n"); dev = Pm_GetDefaultInputDeviceID(); } /* open it for input */ PSF(perr, Pm_OpenInput, (&stream, dev, NULL, 1024, NULL, NULL)); PSF(perr, Pm_SetFilter, (stream, PM_FILT_ACTIVE | PM_FILT_SYSEX)); while (1) Pt_Sleep(1<<31); return 0; }
void NxMidiManager::GetMidiOutputList( std::vector<std::string> & MidiOutputList ) { for (int i = 0; i < Pm_CountDevices(); i++) { const PmDeviceInfo *info = Pm_GetDeviceInfo(i); if( info->output ) { MidiOutputList.push_back( string( info->name ) ); } } }
static PmDeviceInfo *portMidi_getDeviceInfo(int dev, int output) { int i; i = portMidi_getRealDeviceID(dev, output); if (UNLIKELY(i < 0)) return NULL; return ((PmDeviceInfo*)Pm_GetDeviceInfo((PmDeviceID) i)); }
int keyboard_init() { Pm_Initialize(); const PmDeviceInfo* dev_info = Pm_GetDeviceInfo(KEYBOARD_DEV_ID); if (dev_info) { Pm_OpenInput(&midi_stream, KEYBOARD_DEV_ID, NULL, KEYBOARD_MAX_EVENTS, NULL, NULL); return 1; } return 0; }
void NxMidiManager::ListMidiOutputs() { Midi_Outputs.clear(); for (int i = 0; i < Pm_CountDevices(); i++) { const PmDeviceInfo *info = Pm_GetDeviceInfo(i); if( info->output ) { Midi_Outputs.insert( make_pair( i , string( info->name ) ) ); } } }
QStringList PortMidiDriver::deviceOutList() const { QStringList ol; int interf = Pm_CountDevices(); for (PmDeviceID id = 0; id < interf; id++) { const PmDeviceInfo* info = Pm_GetDeviceInfo((PmDeviceID)id); if(info->output) ol.append(QString(info->interf) + "," + QString(info->name)); } return ol; }
std::vector<std::string> MidiSession::getDevices() { auto numMidiInputs = Pm_CountDevices(); std::vector<std::string> devices; for (auto input = 0; input < numMidiInputs; input++) { std::string device = Pm_GetDeviceInfo(input)->name; devices.emplace_back(device); } return devices; }
int port_init_seq() { //if(seq_handle!=NULL) return 1; pm_status=Pm_Initialize(); if(pm_status!=pmNoError) { fprintf(stderr, "Error initialising PortMIDI\n"); return 0; } int i; const PmDeviceInfo *pm_dev_info; int num_devices=Pm_CountDevices(); printf("Available MIDI devices:\n"); for(i=0; i<num_devices; i++) { pm_dev_info=Pm_GetDeviceInfo(i); if(pm_dev_info->input) printf("%d: %s\n", i, pm_dev_info->name); } printf("\n"); pm_status=Pm_OpenInput(&pm_stream, midiport, DRIVER_INFO, INPUT_BUFFER_SIZE, NULL, NULL); if(pm_status!=pmNoError) { fprintf(stderr, "Error opening MIDI input device\n"); } /* if(snd_seq_open(&seq_handle, "default", SND_SEQ_OPEN_INPUT, 0)<0) { fprintf(stderr, "Error opening ALSA sequencer.\n"); return 0; } snd_seq_set_client_name(seq_handle, clientname); in_port=snd_seq_create_simple_port(seq_handle, portname, SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE, SND_SEQ_PORT_TYPE_APPLICATION); if(in_port<0) { fprintf(stderr, "Error creating sequencer port.\n"); return 0; } npfd=snd_seq_poll_descriptors_count(seq_handle, POLLIN); pfd=(struct pollfd *)malloc(npfd*sizeof(struct pollfd)); snd_seq_poll_descriptors(seq_handle, pfd, npfd, POLLIN); */ return 1; }
int PortMidiDriver::getDeviceOut(const QString& interfaceAndName) { int interf = Pm_CountDevices(); for (int id = 0; id < interf; id++) { const PmDeviceInfo* info = Pm_GetDeviceInfo((PmDeviceID)id); if (info->output) { if (QString(info->interf) + "," + QString(info->name) == interfaceAndName) return id; } } return -1; }
void osd_list_midi_devices(void) { #ifndef DISABLE_MIDI int num_devs = Pm_CountDevices(); const PmDeviceInfo *pmInfo; printf("\n"); if (num_devs == 0) { printf("No MIDI ports were found\n"); return; } printf("MIDI input ports:\n"); for (int i = 0; i < num_devs; i++) { pmInfo = Pm_GetDeviceInfo(i); if (pmInfo->input) { printf("%s %s\n", pmInfo->name, (i == Pm_GetDefaultInputDeviceID()) ? "(default)" : ""); } } printf("\nMIDI output ports:\n"); for (int i = 0; i < num_devs; i++) { pmInfo = Pm_GetDeviceInfo(i); if (pmInfo->output) { printf("%s %s\n", pmInfo->name, (i == Pm_GetDefaultOutputDeviceID()) ? "(default)" : ""); } } #else printf("\nMIDI is not supported in this build\n"); #endif }
int PortMidiDriver::getDeviceIn(const QString& name) { int interf = Pm_CountDevices(); for (int id = 0; id < interf; id++) { const PmDeviceInfo* info = Pm_GetDeviceInfo((PmDeviceID)id); if (info->input) { QString n = QString(info->interf) + "," + QString(info->name); if (n == name) return id; } } return -1; }
osd_midi_device *osd_open_midi_output(const char *devname) { int num_devs = Pm_CountDevices(); int found_dev = -1; const PmDeviceInfo *pmInfo; PortMidiStream *stm; osd_midi_device *ret; if (!strcmp("default", devname)) { found_dev = Pm_GetDefaultOutputDeviceID(); } else { for (int i = 0; i < num_devs; i++) { pmInfo = Pm_GetDeviceInfo(i); if (pmInfo->output) { if (!strcmp(devname, pmInfo->name)) { found_dev = i; break; } } } } if (found_dev >= 0) { if (Pm_OpenOutput(&stm, found_dev, NULL, 100, NULL, NULL, 0) == pmNoError) { ret = (osd_midi_device *)osd_malloc(sizeof(osd_midi_device)); memset(ret, 0, sizeof(osd_midi_device)); ret->pmStream = stm; return ret; } else { printf("Couldn't open PM device\n"); return NULL; } } else { return NULL; } return NULL; }
/// Gets the lists of names and lists of labels which are /// used in the choice controls. /// The names are what the user sees in the wxChoice. /// The corresponding labels are what gets stored. void MidiIOPrefs::GetNamesAndLabels() { // Gather list of hosts. Only added hosts that have devices attached. int nDevices = Pm_CountDevices(); for (int i = 0; i < nDevices; i++) { const PmDeviceInfo *info = Pm_GetDeviceInfo(i); if (info->output || info->input) { //should always happen wxString name(info->interf, wxConvLocal); if (mHostNames.Index(name) == wxNOT_FOUND) { mHostNames.Add(name); mHostLabels.Add(name); } } } }
PmDeviceID get_portmidi_device_id (char const *name, gboolean output) { PmError err = Pm_InitializeWrapper (); if (err != pmNoError) { return pmNoDevice; } PmDeviceID ret = pmNoDevice; if (g_strcmp0 (name, "default") == 0) { if (output) { ret = Pm_GetDefaultOutputDeviceID (); goto out; } else { ret = Pm_GetDefaultInputDeviceID (); goto out; } } int num = Pm_CountDevices (); int i; for (i = 0; i < num; ++i) { PmDeviceInfo const *info = Pm_GetDeviceInfo (i); char *s = g_strdup_printf ("%s: %s", info->interf, info->name); // check if the device type (input/output) and name matches if (((output && info->output) || (!output && info->input)) && g_strcmp0 (name, s) == 0) { ret = i; g_free (s); break; } g_free (s); } out: Pm_TerminateWrapper (); return ret; }
static int find_device_id_out(char* name) { const PmDeviceInfo *di; for(int i= 0; ; i++) { di= Pm_GetDeviceInfo(i); if(!di) break; if(strstr(di->name, name) && di->output) { printf("found out device '%s' with interf '%s'\n", di->name, di->interf); return i; } } return -1; }
/// Gets the lists of names and lists of labels which are /// used in the choice controls. /// The names are what the user sees in the wxChoice. /// The corresponding labels are what gets stored. void MidiIOPrefs::GetNamesAndLabels() { // Gather list of hosts. Only added hosts that have devices attached. Pm_Terminate(); // close and open to refresh device lists Pm_Initialize(); int nDevices = Pm_CountDevices(); for (int i = 0; i < nDevices; i++) { const PmDeviceInfo *info = Pm_GetDeviceInfo(i); if (info->output || info->input) { //should always happen wxString name = wxSafeConvertMB2WX(info->interf); if (mHostNames.Index(name) == wxNOT_FOUND) { mHostNames.Add(name); mHostLabels.Add(name); } } } }
static int portMidi_getRealDeviceID(int dev, int output) { int i, j, cnt; PmDeviceInfo *info; cnt = (int)Pm_CountDevices(); i = j = -1; while (++i < cnt) { info = (PmDeviceInfo*)Pm_GetDeviceInfo((PmDeviceID) i); if ((output && !(info->output)) || (!output && !(info->input))) continue; if (++j == dev) return i; } return -1; }
PyObject * portmidi_list_devices() { int i; printf("MIDI devices:\n"); for (i = 0; i < Pm_CountDevices(); i++) { const PmDeviceInfo *info = Pm_GetDeviceInfo(i); if (info->input && info->output) printf("%d: IN/OUT, name: %s, interface: %s\n", i, info->name, info->interf); else if (info->input) printf("%d: IN, name: %s, interface: %s\n", i, info->name, info->interf); else if (info->output) printf("%d: OUT, name: %s, interface: %s\n", i, info->name, info->interf); } printf("\n"); Py_RETURN_NONE; }
static int portMidi_getPackedDeviceID(int dev, int output) { int i, j, cnt; PmDeviceInfo *info; cnt = (int)Pm_CountDevices(); i = j = -1; while (++i < cnt) { info = (PmDeviceInfo*)Pm_GetDeviceInfo((PmDeviceID) i); if ((output && info->output) || (!output && info->input)) j++; if (i == dev) return j; } return -1; }
bool osd_midi_device_pm::open_output(const char *devname) { int num_devs = Pm_CountDevices(); int found_dev = -1; const PmDeviceInfo *pmInfo; PortMidiStream *stm; if (!strcmp("default", devname)) { found_dev = Pm_GetDefaultOutputDeviceID(); } else { for (int i = 0; i < num_devs; i++) { pmInfo = Pm_GetDeviceInfo(i); if (pmInfo->output) { if (!strcmp(devname, pmInfo->name)) { found_dev = i; break; } } } } if (found_dev >= 0) { if (Pm_OpenOutput(&stm, found_dev, NULL, 100, NULL, NULL, 0) == pmNoError) { pmStream = stm; return true; } else { printf("Couldn't open PM device\n"); return false; } } else { return false; } return false; }
void PortMidiSettingsPage::populateDeviceLists() { int i; for (i = 0; i < Pm_CountDevices(); i++) { const PmDeviceInfo *deviceInfo = Pm_GetDeviceInfo(i); if (!deviceInfo) { continue; } if (deviceInfo->input) { inputDeviceList->addItem(QString::fromLocal8Bit(deviceInfo->name)); } if (deviceInfo->output) { outputDeviceList->addItem(QString::fromLocal8Bit(deviceInfo->name)); } } }
osd_midi_device *osd_open_midi_input(const char *devname) { #ifndef DISABLE_MIDI int num_devs = Pm_CountDevices(); int found_dev = -1; const PmDeviceInfo *pmInfo; PortMidiStream *stm; osd_midi_device *ret; for (int i = 0; i < num_devs; i++) { pmInfo = Pm_GetDeviceInfo(i); if (pmInfo->input) { if (!strcmp(devname, pmInfo->name)) { found_dev = i; break; } } } if (found_dev >= 0) { if (Pm_OpenInput(&stm, found_dev, NULL, RX_EVENT_BUF_SIZE, NULL, NULL) == pmNoError) { ret = (osd_midi_device *)osd_malloc(sizeof(osd_midi_device)); memset(ret, 0, sizeof(osd_midi_device)); ret->pmStream = stm; return ret; } else { printf("Couldn't open PM device\n"); return NULL; } } else { return NULL; } #else return NULL; #endif }