void MIDIDevice::feedBack(t_input_channel channel, t_input_value value) { /* MIDI devices can have only 128 notes or controllers */ if (channel < 128) { snd_seq_event_t ev; MIDIInput* plugin; plugin = static_cast<MIDIInput*> (parent()); Q_ASSERT(plugin != NULL); Q_ASSERT(plugin->alsa() != NULL); Q_ASSERT(m_address != NULL); /* Setup an event structure */ snd_seq_ev_clear(&ev); snd_seq_ev_set_dest(&ev, m_address->client, m_address->port); snd_seq_ev_set_subs(&ev); snd_seq_ev_set_direct(&ev); /* Send control change, channel 1 (0) */ snd_seq_ev_set_controller(&ev, 0, channel, value >> 1); snd_seq_event_output(plugin->alsa(), &ev); snd_seq_drain_output(plugin->alsa()); /* Send note on/off, channel 1 (0) */ if (value == 0) snd_seq_ev_set_noteoff(&ev, 0, channel, 0); else snd_seq_ev_set_noteon(&ev, 0, channel, value >> 1); snd_seq_event_output(plugin->alsa(), &ev); snd_seq_drain_output(plugin->alsa()); }
QString MIDIDevice::infoText() { MIDIInput* plugin = static_cast<MIDIInput*> (parent()); Q_ASSERT(plugin != NULL); QString info; if (plugin->alsa() != NULL) { info += QString("<B>%1</B>").arg(name()); info += QString("<P>"); info += tr("Device is working correctly."); info += QString("</P>"); info += QString("<P>"); info += QString("<B>%1:</B> ").arg(tr("MIDI Channel")); if (midiChannel() < 16) info += QString("%1<BR/>").arg(midiChannel() + 1); else info += QString("%1<BR/>").arg(tr("Any")); info += QString("</P>"); } else { info += QString("<B>%1</B>").arg(tr("Unknown device")); info += QString("<P>"); info += tr("ALSA sequencer interface is not available."); info += QString("</P>"); } return info; }
MIDIInput* MIDIInput::create(MIDIAccess* access, const String& id, const String& manufacturer, const String& name, const String& version, PortState state) { ASSERT(access); MIDIInput* input = new MIDIInput(access, id, manufacturer, name, version, state); input->suspendIfNeeded(); return input; }
QString MIDIDevice::infoText() { MIDIInput* plugin; QString info; plugin = static_cast<MIDIInput*> (parent()); Q_ASSERT(plugin != NULL); if (plugin->alsa() != NULL) { info += QString("<B>%1</B>").arg(name()); info += QString("<P>"); info += QString("Device is working correctly."); info += QString("</P>"); info += QString("<P>"); info += QString("<B>MIDI Channel: </B>%1<BR>") .arg(m_midiChannel + 1); info += QString("<B>Mode: </B>%1") .arg(modeToString(m_mode)); info += QString("</P>"); } else { info += QString("<B>Unknown device</B>"); info += QString("<P>"); info += QString("ALSA sequencer interface is not available."); info += QString("</P>"); } return info; }
int GMSynthDLL::MidiIn(int onoff, int device) { if (onoff) { kbd.SetDevice(device, 0); kbd.Start(); } else kbd.Stop(); return 0; }
void MIDIDevice::feedBack(t_input_channel channel, t_input_value value) { /* MIDI devices can have only 128 notes or controllers */ if (channel < 128) { snd_seq_event_t ev; MIDIInput* plugin; plugin = static_cast<MIDIInput*> (parent()); Q_ASSERT(plugin != NULL); Q_ASSERT(plugin->alsa() != NULL); Q_ASSERT(m_address != NULL); /* Setup an event structure */ snd_seq_ev_clear(&ev); snd_seq_ev_set_dest(&ev, m_address->client, m_address->port); snd_seq_ev_set_subs(&ev); snd_seq_ev_set_direct(&ev); char scaled = static_cast <char> (SCALE(double(value), double(0), double(KInputValueMax), double(0), double(127))); if (m_mode == ControlChange) { /* Send control change */ snd_seq_ev_set_controller(&ev, midiChannel(), channel, scaled); snd_seq_event_output(plugin->alsa(), &ev); snd_seq_drain_output(plugin->alsa()); } else { /* Send note on/off */ if (value == 0) { snd_seq_ev_set_noteoff(&ev, midiChannel(), channel, scaled); } else { snd_seq_ev_set_noteon(&ev, midiChannel(), channel, scaled); } snd_seq_event_output(plugin->alsa(), &ev); snd_seq_drain_output(plugin->alsa()); } } }
void MIDIDevice::extractName() { MIDIInput* plugin = static_cast<MIDIInput*> (parent()); if (plugin == NULL || plugin->alsa() == NULL || m_address == NULL) return; snd_seq_port_info_t* portInfo = NULL; snd_seq_port_info_alloca(&portInfo); int r = snd_seq_get_any_port_info(plugin->alsa(), m_address->client, m_address->port, portInfo); if (r == 0) m_name = QString(snd_seq_port_info_get_name(portInfo)); else m_name = QString("ERROR"); }
MIDIInputMap* MIDIAccess::inputs() const { HeapVector<Member<MIDIInput>> inputs; HashSet<String> ids; for (size_t i = 0; i < m_inputs.size(); ++i) { MIDIInput* input = m_inputs[i]; if (input->getState() != PortState::DISCONNECTED) { inputs.append(input); ids.add(input->id()); } } if (inputs.size() != ids.size()) { // There is id duplication that violates the spec. inputs.clear(); } return new MIDIInputMap(inputs); }
ElaborationUnit* InputOutputFactory::getMidiIn(int instanceIndex) { int num; //Check if a MIDIIn device is available if( (num = MIDIInput::GetMIDIDevicesNumber()) > 0 ) { //First of all, create the object MIDIInput *pMidiIn = new MIDIInput(moduleServices); //Check for a MIDI device available for(int i=0;i<num;++i) { //if( !m_MIDIInDescriptions[i].m_bAllocated ) //{ HMIDIIN hMIDIIn; DWORD ThId; HANDLE h = ::CreateThread(NULL,0,&MIDIThreadProc,pMidiIn,0,&ThId); assert(h); //Try to allocate it //MMRESULT mmres = ::midiInOpen(&hMIDIIn,i,(DWORD_PTR) &MIDIInput::MidiInProc,(DWORD_PTR) pMIDIInput,CALLBACK_FUNCTION); MMRESULT mmres = ::midiInOpen(&hMIDIIn,i,(DWORD_PTR) ThId,NULL,CALLBACK_THREAD); if( mmres == MMSYSERR_NOERROR ) { //Object created successfully pMidiIn->SetMIDIInHandle(hMIDIIn); //m_MIDIInDescriptions[i].m_bAllocated = true; addElaborationUnit(pMidiIn); return pMidiIn; } else { //Stop the Thread if(h) ::CloseHandle(h); delete pMidiIn; return NULL; } //} } delete pMidiIn; return NULL; } else return NULL; }
MIDIInputMap* MIDIAccess::inputs() const { HeapHashMap<String, Member<MIDIInput> > inputs; size_t inactiveCount = 0; for (size_t i = 0; i < m_inputs.size(); ++i) { MIDIInput* input = m_inputs[i]; if (input->isActive()) inputs.add(input->id(), input); else inactiveCount++; } if ((inputs.size() + inactiveCount) != m_inputs.size()) { // There is id duplication that violates the spec. inputs.clear(); } return new MIDIInputMap(inputs); }
void MIDIDevice::feedBack(quint32 channel, uchar value) { MIDIInput* plugin = static_cast<MIDIInput*> (parent()); Q_ASSERT(plugin != NULL); Q_ASSERT(plugin->alsa() != NULL); Q_ASSERT(m_address != NULL); uchar cmd = 0; uchar data1 = 0; uchar data2 = 0; bool d2v = false; if (QLCMIDIProtocol::feedbackToMidi(channel, value, midiChannel(), &cmd, &data1, &data2, &d2v) == true) { /* Setup an event structure */ snd_seq_event_t ev; snd_seq_ev_clear(&ev); snd_seq_ev_set_dest(&ev, m_address->client, m_address->port); snd_seq_ev_set_subs(&ev); snd_seq_ev_set_direct(&ev); if (MIDI_CMD(cmd) == MIDI_NOTE_OFF) { /* Send data as note off command */ snd_seq_ev_set_noteoff(&ev, midiChannel(), data1, data2); snd_seq_event_output(plugin->alsa(), &ev); snd_seq_drain_output(plugin->alsa()); } else if (MIDI_CMD(cmd) == MIDI_NOTE_ON) { /* Send data as note on command */ snd_seq_ev_set_noteon(&ev, midiChannel(), data1, data2); snd_seq_event_output(plugin->alsa(), &ev); snd_seq_drain_output(plugin->alsa()); } else if (MIDI_CMD(cmd) == MIDI_CONTROL_CHANGE) { /* Send data as control change command */ snd_seq_ev_set_controller(&ev, midiChannel(), data1, data2); snd_seq_event_output(plugin->alsa(), &ev); snd_seq_drain_output(plugin->alsa()); } } }
void MIDIDevice::extractName() { snd_seq_port_info_t* portInfo = NULL; MIDIInput* plugin; int r; plugin = static_cast<MIDIInput*> (parent()); Q_ASSERT(plugin != NULL); Q_ASSERT(plugin->alsa() != NULL); Q_ASSERT(m_address != NULL); snd_seq_port_info_alloca(&portInfo); r = snd_seq_get_any_port_info(plugin->alsa(), m_address->client, m_address->port, portInfo); if (r == 0) m_name = QString(snd_seq_port_info_get_name(portInfo)); else m_name = QString("ERROR"); }
GMSynthDLL(Opaque w) { magic = GMSYNTH_MAGIC; sbnk = 0; seqMode = seqOff; seq.SetMaxNotes(32); kbd.SetSequenceInfo(&seq, &inmgr); wvf.SetBufSize(30); ldTm = 0.5; live = 1; stTime = 0; endTime = 0; #ifdef _WIN32 SetWaveDevice(NULL); wavWnd = (HWND)w; #endif #ifdef UNIX SetWaveDevice((void*)"hw:0"); #endif }