void MIDIOut::initALSA() { snd_seq_client_info_t* client = NULL; /* Destroy the old handle */ if (m_alsa != NULL) snd_seq_close(m_alsa); m_alsa = NULL; /* Destroy the plugin's own address */ if (m_address != NULL) delete m_address; m_address = NULL; /* Open the sequencer interface */ if (snd_seq_open(&m_alsa, "default", SND_SEQ_OPEN_DUPLEX, 0) != 0) { qWarning() << "Unable to open ALSA interface!"; m_alsa = NULL; return; } /* Set current client information */ snd_seq_client_info_alloca(&client); snd_seq_set_client_name(m_alsa, name().toAscii()); snd_seq_get_client_info(m_alsa, client); /* Create an application-level port */ m_address = new snd_seq_addr_t; m_address->port = snd_seq_create_simple_port(m_alsa, "__QLC__output", SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ, SND_SEQ_PORT_TYPE_MIDI_GENERIC); m_address->client = snd_seq_client_info_get_client(client); }
void Alsa::initialize() { // Set up the ALSA sequencer client. snd_seq_t *seq; int result = snd_seq_open( &seq, "default", SND_SEQ_OPEN_OUTPUT, SND_SEQ_NONBLOCK ); if ( result < 0 ) { std::cerr << "error: CxxMidi::Output::Alsa::initialize: error creating ALSA sequencer client object" << std::endl; } // Set client name. snd_seq_set_client_name( seq, "CxxMidi (RtMidi) output" ); // Save our api-specific connection information. _apiData= new AlsaMidiData; _apiData->seq = seq; _apiData->vport = -1; _apiData->bufferSize = 32; _apiData->coder = 0; _apiData->buffer = 0; result = snd_midi_event_new( _apiData->bufferSize, &_apiData->coder ); if ( result < 0 ) { delete _apiData; std::cerr << "error: CxxMidi::Output::Alsa::initialize: error initializing MIDI event parser" << std::endl; return; } _apiData->buffer = (unsigned char *) malloc( _apiData->bufferSize ); if ( _apiData->buffer == NULL ) { delete _apiData; std::cerr << "error: CxxMidi::Output::Alsa::initialize: error allocating buffer memory" << std::endl; } snd_midi_event_init( _apiData->coder ); }
bool QMidi::initMidiOut(QString outDeviceId) { #if defined(Q_OS_WIN) midiOutOpen(&midiOutPtr,outDeviceId.toInt(),0,0,CALLBACK_NULL); #elif defined(Q_OS_LINUX) int err = snd_seq_open(&midiOutPtr, "default", SND_SEQ_OPEN_OUTPUT, 0); if(err < 0) { return false; } snd_seq_set_client_name(midiOutPtr, "QtMidi"); snd_seq_create_simple_port(midiOutPtr, "Output Port", SND_SEQ_PORT_CAP_READ, SND_SEQ_PORT_TYPE_MIDI_GENERIC); QStringList l = outDeviceId.split(":"); int client = l.at(0).toInt(); int port = l.at(1).toInt(); snd_seq_connect_to(midiOutPtr, 0, client, port); #elif defined(Q_OS_HAIKU) midiOutConsumer = BMidiRoster::FindConsumer(outDeviceId.toInt()); if(midiOutConsumer == NULL) { return false; } midiOutLocProd = new BMidiLocalProducer("QtMidi"); if(!midiOutLocProd->IsValid()) { midiOutLocProd->Release(); return false; } // some error ?? midiOutLocProd->Register(); if(midiOutLocProd->Connect(midiOutConsumer) != B_OK) { return false; } #endif myOutDeviceId = outDeviceId; return true; }
static snd_seq_t* createDevice (const bool forInput, const String& deviceNameToOpen) { snd_seq_t* seqHandle = 0; if (snd_seq_open (&seqHandle, "default", forInput ? SND_SEQ_OPEN_INPUT : SND_SEQ_OPEN_OUTPUT, 0) == 0) { snd_seq_set_client_name (seqHandle, (const char*) (forInput ? (deviceNameToOpen + T(" Input")) : (deviceNameToOpen + T(" Output")))); const int portId = snd_seq_create_simple_port (seqHandle, forInput ? "in" : "out", forInput ? (SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE) : (SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ), forInput ? SND_SEQ_PORT_TYPE_APPLICATION : SND_SEQ_PORT_TYPE_MIDI_GENERIC); if (portId < 0) { snd_seq_close (seqHandle); seqHandle = 0; } } return seqHandle; }
void MidiEnumeratorPrivate::initAlsa() { qDebug() << Q_FUNC_INFO; if (snd_seq_open(&m_alsa, "default", SND_SEQ_OPEN_DUPLEX, 0) != 0) { qWarning() << "Unable to open ALSA interface!"; m_alsa = NULL; return; } /* Set current client information */ snd_seq_client_info_t* client = NULL; snd_seq_client_info_alloca(&client); snd_seq_set_client_name(m_alsa, "qlcplus"); snd_seq_get_client_info(m_alsa, client); /* Create an application-level port */ m_address = new snd_seq_addr_t; m_address->port = snd_seq_create_simple_port(m_alsa, "__QLC__", SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ | SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE, SND_SEQ_PORT_TYPE_MIDI_GENERIC); m_address->client = snd_seq_client_info_get_client(client); /* Create input thread */ m_inputThread = new AlsaMidiInputThread(m_alsa, m_address, this); }
static int alsa_seqmidi_attach(alsa_midi_t *m) { alsa_seqmidi_t *self = (alsa_seqmidi_t*) m; int err; debug_log("midi: attach"); if (self->seq) return -EALREADY; if ((err = snd_seq_open(&self->seq, "hw", SND_SEQ_OPEN_DUPLEX, 0)) < 0) { error_log("failed to open alsa seq"); return err; } snd_seq_set_client_name(self->seq, self->alsa_name); self->port_id = snd_seq_create_simple_port(self->seq, "port", SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_WRITE #ifndef JACK_MIDI_DEBUG |SND_SEQ_PORT_CAP_NO_EXPORT #endif ,SND_SEQ_PORT_TYPE_APPLICATION); self->client_id = snd_seq_client_id(self->seq); self->queue = snd_seq_alloc_queue(self->seq); snd_seq_start_queue(self->seq, self->queue, 0); stream_attach(self, PORT_INPUT); stream_attach(self, PORT_OUTPUT); snd_seq_nonblock(self->seq, 1); return 0; }
QMap<QString,QString> QMidi::outDeviceNames() { QMap<QString,QString> ret; #if defined(Q_OS_WIN) int numDevs = midiOutGetNumDevs(); if(numDevs == 0) { return ret; } for(int i = 0;i<numDevs;i++) { MIDIOUTCAPS* devCaps = new MIDIOUTCAPS; midiOutGetDevCaps(i,devCaps,sizeof(*devCaps)); ret.insert(QString::number(i),QString::fromWCharArray(devCaps->szPname)); delete devCaps; } #elif defined(Q_OS_LINUX) snd_seq_client_info_t *cinfo; snd_seq_port_info_t *pinfo; int client; int err; snd_seq_t *handle; err = snd_seq_open(&handle, "hw", SND_SEQ_OPEN_DUPLEX, 0); if(err < 0) { /* Could not open sequencer!! use snd_strerror(errno) to get error. */ return ret; } snd_seq_client_info_alloca(&cinfo); snd_seq_client_info_set_client(cinfo, -1); while(snd_seq_query_next_client(handle, cinfo) >= 0) { client = snd_seq_client_info_get_client(cinfo); snd_seq_port_info_alloca(&pinfo); snd_seq_port_info_set_client(pinfo, client); snd_seq_port_info_set_port(pinfo, -1); while(snd_seq_query_next_port(handle, pinfo) >= 0) { int cap = (SND_SEQ_PORT_CAP_SUBS_WRITE|SND_SEQ_PORT_CAP_WRITE); if((snd_seq_port_info_get_capability(pinfo) & cap) == cap) { QString port = QString::number(snd_seq_port_info_get_client(pinfo)); port += ":" + QString::number(snd_seq_port_info_get_port(pinfo)); QString name = snd_seq_client_info_get_name(cinfo); ret.insert(port,name); } } } #elif defined(Q_OS_HAIKU) bool OK = true; int32 id = 0; while(OK) { BMidiConsumer* c = BMidiRoster::NextConsumer(&id); if(c != NULL) { ret.insert(QString::number(id),QString::fromUtf8(c->Name())); c->Release(); } else { OK = false; } } #endif return ret; }
static snd_seq_t *create_alsa_seq(const char *client_name,bool isinput){ snd_seq_t * seq; int err; err = snd_seq_open(&seq, "default", SND_SEQ_OPEN_DUPLEX, 0); if (err){ printf( "Could not open ALSA sequencer, aborting\n\n%s\n\n" "Make sure you have configure ALSA properly and that\n" "/proc/asound/seq/clients exists and contains relevant\n" "devices.\n", snd_strerror (err)); return NULL; } snd_seq_set_client_name (seq, client_name); err = snd_seq_create_simple_port (seq, isinput==true?"Input":"Output", (isinput==true?SND_SEQ_PORT_CAP_WRITE:SND_SEQ_PORT_CAP_READ)|SND_SEQ_PORT_CAP_DUPLEX| SND_SEQ_PORT_CAP_SUBS_READ|SND_SEQ_PORT_CAP_SUBS_WRITE, SND_SEQ_PORT_TYPE_APPLICATION|SND_SEQ_PORT_TYPE_SPECIFIC); if (err){ printf ( "Could not create ALSA port, aborting\n\n%s\n", snd_strerror (err)); snd_seq_close(seq); return NULL; } return seq; }
void RKR::InitMIDI () { // Open Alsa Seq int alsaport_in; int err = snd_seq_open (&midi_in, "default", SND_SEQ_OPEN_INPUT, 0); if (err < 0) printf ("Cannot activate ALSA seq client\n"); snd_seq_set_client_name (midi_in, "rakarrack"); snd_config_update_free_global (); char portname[50]; // Create Alsa Seq Client sprintf (portname, "rakarrack IN"); alsaport_in = snd_seq_create_simple_port (midi_in, portname, SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE, SND_SEQ_PORT_TYPE_SYNTH); }
SeqDriver::SeqDriver(QList<MidiMap *> *p_midiMapList, QWidget *parent) : QWidget(parent), modified(false) { int err; midiMapList = p_midiMapList; portCount = 0; discardUnmatched = true; portUnmatched = 0; clientid = -1; err = snd_seq_open(&seq_handle, "hw", SND_SEQ_OPEN_DUPLEX, 0); if (err < 0) { qWarning("Error opening ALSA sequencer (%s).", snd_strerror(err)); exit(1); } snd_seq_set_client_name(seq_handle, PACKAGE); clientid = snd_seq_client_id(seq_handle); portid_in = snd_seq_create_simple_port(seq_handle, "in", SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE, SND_SEQ_PORT_TYPE_APPLICATION); if (portid_in < 0) { qWarning("Error creating sequencer port (%s).", snd_strerror(portid_in)); exit(1); } }
void midi_register() { //open a new alsa midi client if (snd_seq_open(&midi_client, "default", SND_SEQ_OPEN_DUPLEX, 0) < 0) { fprintf(stderr,"coud not open a new midi client\n"); return; } //set the client's name snd_seq_set_client_name(midi_client, "Launchpad"); //open a new midi output port midi_out = snd_seq_create_simple_port(midi_client, "Out", SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ, SND_SEQ_PORT_TYPE_PORT); if (midi_out < 0) { fprintf(stderr,"could not open the midi out port\n"); return; } midi_in = snd_seq_create_simple_port(midi_client, "In", SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE, SND_SEQ_PORT_TYPE_PORT); if (midi_in < 0) { fprintf(stderr,"could not open the midi in port\n"); return; } }
// Constructor. qxgeditMidiDevice::qxgeditMidiDevice ( const QString& sClientName ) : QObject(NULL) { // Set pseudo-singleton reference. g_pMidiDevice = this; m_pAlsaSeq = NULL; m_iAlsaClient = -1; m_iAlsaPort = -1; m_pInputThread = NULL; // Open new ALSA sequencer client... if (snd_seq_open(&m_pAlsaSeq, "hw", SND_SEQ_OPEN_DUPLEX, 0) >= 0) { // Set client identification... QString sName = sClientName; snd_seq_set_client_name(m_pAlsaSeq, sName.toLatin1().constData()); m_iAlsaClient = snd_seq_client_id(m_pAlsaSeq); // Create duplex port sName += " MIDI 1"; m_iAlsaPort = snd_seq_create_simple_port(m_pAlsaSeq, sName.toLatin1().constData(), SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE | SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ, SND_SEQ_PORT_TYPE_MIDI_GENERIC | SND_SEQ_PORT_TYPE_APPLICATION); // Create and start our own MIDI input queue thread... m_pInputThread = new qxgeditMidiInputThread(this); m_pInputThread->start(QThread::TimeCriticalPriority); } }
int main() { snd_seq_t *handle; int err; err = snd_seq_open(&handle, "default", SND_SEQ_OPEN_INPUT, 0); if (err < 0) { fprintf(stderr, "%s\n", snd_strerror(-err)); exit(1); } snd_seq_set_client_name(handle, "Yo!"); int port_number = snd_seq_create_simple_port(handle, "my port", SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE, SND_SEQ_PORT_TYPE_MIDI_GENERIC); snd_seq_event_t *event; for (;;){ snd_seq_event_input(handle, &event); printf("Type: %d\n", event->type); if (snd_seq_ev_is_note_type(event)){ printf("Note: %d\n", event->data.note.note); printf("Velocity: %d\n", event->data.note.velocity); } printf("Source: %d:%d\n", event->source.client, event->source.port); printf("Destination: %d:%d\n", event->dest.client, event->dest.port); } return 0; }
int seq_open() { unsigned int caps; if (!seq_opened) { /* sequencer opening */ if (snd_seq_open(&seq_handle, "hw", SND_SEQ_OPEN_OUTPUT, 0)) { fprintf(stderr, "Error opening ALSA sequencer.\n"); return(-1); } /* our client id */ my_client = snd_seq_client_id(seq_handle); /* set client info */ snd_seq_set_client_name(seq_handle, DEFAULT_NAME); /* create port */ caps = SND_SEQ_PORT_CAP_READ; if (seq_client == SND_SEQ_ADDRESS_SUBSCRIBERS) caps |= SND_SEQ_PORT_CAP_SUBS_READ; my_port = snd_seq_create_simple_port(seq_handle, DEFAULT_NAME, caps,SND_SEQ_PORT_TYPE_MIDI_GENERIC | SND_SEQ_PORT_TYPE_APPLICATION); if (my_port < 0) { fprintf(stderr, "can't create port\n"); snd_seq_close(seq_handle); return 0; } /* subscribe to MIDI port */ if (seq_client != SND_SEQ_ADDRESS_SUBSCRIBERS) { if (snd_seq_connect_to(seq_handle, my_port, seq_client, seq_port) < 0) { fprintf(stderr, "can't subscribe to MIDI port (%d:%d)\n", seq_client, seq_port); snd_seq_close(seq_handle); return 0; } } } seq_opened = 1; return 1; }
bool Midi2UdpThread::initSeq() { if(snd_seq_open(&seq_handle, "default", SND_SEQ_OPEN_INPUT, 0) < 0) { printf("midi2udp: Error opening ALSA sequencer.\n"); return false; } snd_seq_set_client_name(seq_handle, "DSMIDIWIFI MIDI2UDP"); char portname[64] = "DSMIDIWIFI MIDI2UDP IN"; int res = midi_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(res < 0) { printf("midi2udp: Error creating MIDI port!\n"); snd_seq_close(seq_handle); return false; } res = snd_midi_event_new(MAX_MIDI_MESSAGE_LENGTH, &eventparser); if(res != 0) { printf("midi2udp: Error making midi event parser!\n"); snd_seq_close(seq_handle); return false; } snd_midi_event_init(eventparser); midi_event = (snd_seq_event_t*)malloc(sizeof(snd_seq_event_t)); return true; }
int midi_open(void) { if (snd_seq_open(&alsaClient, "hw", SND_SEQ_OPEN_DUPLEX, 0) < 0) { ghss_debug(GDB_ERROR, ": failed to open ALSA sequencer interface"); return 0; } snd_seq_set_client_name(alsaClient, host_name); alsa_client_id = snd_seq_client_id(alsaClient); if ((alsa_port_id = snd_seq_create_simple_port (alsaClient, "input", SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE, SND_SEQ_PORT_TYPE_APPLICATION)) < 0) { ghss_debug(GDB_ERROR, ": failed to create ALSA sequencer port"); return 0; } alsaClient_npfd = snd_seq_poll_descriptors_count(alsaClient, POLLIN); alsaClient_pfd = (struct pollfd *)calloc(1, alsaClient_npfd * sizeof(struct pollfd)); snd_seq_poll_descriptors(alsaClient, alsaClient_pfd, alsaClient_npfd, POLLIN); ghss_debug(GDB_ALWAYS, ": listening using ALSA MIDI"); return 1; }
void DeviceManager::init() { int err; /* open sequencer */ err = snd_seq_open(&handle, "default", SND_SEQ_OPEN_DUPLEX, 0); if(err < 0){ D("Failed opening sequencer"); return; } /* set our client's name */ err = snd_seq_set_client_name(handle, "libSeq"); if(err < 0){ D("Failed setting name"); return; } err = snd_seq_create_simple_port(handle, "libSeq", SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE, SND_SEQ_PORT_TYPE_MIDI_GENERIC | SND_SEQ_PORT_TYPE_APPLICATION); if(err < 0){ D("Failed creating port"); return; } }
static PyObject * alsaseq_client(PyObject *self /* Not used */, PyObject *args) { const char * client_name; if (!PyArg_ParseTuple(args, "siii", &client_name, &ninputports, &noutputports, &createqueue ) ) return NULL; if ( ninputports > maximum_nports || noutputports > maximum_nports ) { printf( "Only %d ports of each are allowed.\n", maximum_nports ); exit( 1 ); } int portid, n; if (snd_seq_open(&seq_handle, "default", SND_SEQ_OPEN_DUPLEX, 0) < 0) { fprintf(stderr, "Error creating ALSA client.\n"); exit(1); } snd_seq_set_client_name(seq_handle, client_name ); if ( createqueue ) queue_id = snd_seq_alloc_queue(seq_handle); else queue_id = SND_SEQ_QUEUE_DIRECT; for ( n=0; n < ninputports; n++ ) { if (( portid = snd_seq_create_simple_port(seq_handle, "Input port", SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE, SND_SEQ_PORT_TYPE_APPLICATION)) < 0) { fprintf(stderr, "Error creating input port %d.\n", n ); exit(1); } if( createqueue ) { /* set timestamp info of port */ snd_seq_port_info_t *pinfo; snd_seq_port_info_alloca(&pinfo); snd_seq_get_port_info( seq_handle, portid, pinfo ); snd_seq_port_info_set_timestamping(pinfo, 1); snd_seq_port_info_set_timestamp_queue(pinfo, queue_id ); snd_seq_port_info_set_timestamp_real( pinfo, 1 ); snd_seq_set_port_info( seq_handle, portid, pinfo ); } } for ( n=0; n < noutputports; n++ ) { if (( portid = snd_seq_create_simple_port(seq_handle, "Output port", SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_SUBS_READ, SND_SEQ_PORT_TYPE_APPLICATION)) < 0) { fprintf(stderr, "Error creating output port %d.\n", n ); exit(1); } } firstoutputport = ninputports; lastoutputport = noutputports + ninputports - 1; Py_INCREF(Py_None); return Py_None; }
void JVlibForm::init_seq() { if (seq) return; int err = snd_seq_open(&seq, "default", SND_SEQ_OPEN_OUTPUT, 0); check_snd("open sequencer", err); err = snd_seq_set_client_name(seq, "midi_player"); check_snd("set client name", err); int client = snd_seq_client_id(seq); // client # is 128 by default check_snd("get client id", client); }
/* Returned structure pointer is allocated using malloc. */ struct polls * midi_init_alsa(void) { struct polls *polls; int npfd; int synth_port, ctrlr_port; int i; if (snd_seq_open(&seq, "default", SND_SEQ_OPEN_DUPLEX, 0) < 0) { dprintf("Couldn't open ALSA sequencer: %s\n", snd_strerror(errno)); return NULL; } snd_seq_set_client_name(seq, "Xtor"); client = snd_seq_client_id(seq); if (client < 0) { dprintf("Can't get client_id: %d\n", client); return NULL; } dprintf("Client address %d\n", client); synth_port = snd_seq_create_simple_port(seq, "Xtor synth port", SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_READ | SND_SEQ_PORT_CAP_SUBS_WRITE, SND_SEQ_PORT_TYPE_APPLICATION); if (synth_port < 0) { dprintf("Couldn't create synth port: %s\n", snd_strerror(errno)); return NULL; } ports[SYNTH_PORT] = synth_port; ctrlr_port = snd_seq_create_simple_port(seq, "Xtor controller port", SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_READ | SND_SEQ_PORT_CAP_SUBS_WRITE, SND_SEQ_PORT_TYPE_APPLICATION); if (ctrlr_port < 0) { dprintf("Couldn't create controller port: %s\n", snd_strerror(errno)); return NULL; } ports[CTRLR_PORT] = ctrlr_port; /* Fetch poll descriptor(s) for MIDI input (normally only one) */ npfd = snd_seq_poll_descriptors_count(seq, POLLIN); polls = (struct polls *) malloc(sizeof(struct polls) + npfd * sizeof(struct pollfd)); polls->npfd = npfd; snd_seq_poll_descriptors(seq, polls->pollfds, npfd, POLLIN); snd_seq_nonblock(seq, SND_SEQ_NONBLOCK); return polls; }
// create a new client snd_seq_t *open_client() { snd_seq_t *handle; int err; err = snd_seq_open(&handle, "default", SND_SEQ_OPEN_OUTPUT, 0); if (err < 0) return NULL; snd_seq_set_client_name(handle, "Game Drumkit Client"); return handle; }
mastermidibus::mastermidibus () : m_alsa_seq (nullptr), // one pointer m_num_out_buses (0), // or c_max_busses, or what? m_num_in_buses (0), // or c_max_busses, or 1, or what? m_buses_out (), // array of c_max_busses midibus pointers m_buses_in (), // array of c_max_busses midibus pointers m_bus_announce (nullptr), // one pointer m_buses_out_active (), // array of c_max_busses booleans m_buses_in_active (), // array of c_max_busses booleans m_buses_out_init (), // array of c_max_busses booleans m_buses_in_init (), // array of c_max_busses booleans m_init_clock (), // array of c_max_busses clock_e values m_init_input (), // array of c_max_busses booleans m_queue (0), m_ppqn (0), m_bpm (0), m_num_poll_descriptors (0), m_poll_descriptors (nullptr), m_dumping_input (false), m_seq (nullptr), m_mutex () { for (int i = 0; i < c_max_busses; ++i) // why the global? { m_buses_in_active[i] = false; m_buses_out_active[i] = false; m_buses_in_init[i] = false; m_buses_out_init[i] = false; m_init_clock[i] = e_clock_off; m_init_input[i] = false; } #ifdef HAVE_LIBASOUND /* open the sequencer client */ int result = snd_seq_open(&m_alsa_seq, "default", SND_SEQ_OPEN_DUPLEX, 0); if (result < 0) { errprint("snd_seq_open() error"); exit(1); } snd_seq_set_client_name(m_alsa_seq, "seq24"); /* client's name */ m_queue = snd_seq_alloc_queue(m_alsa_seq); /* client's queue */ #endif #ifdef LASH_SUPPORT /* * Notify LASH of our client ID so that it can restore connections. */ if (not_nullptr(global_lash_driver)) global_lash_driver->set_alsa_client_id(snd_seq_client_id(m_alsa_seq)); #endif }
MidiInputDeviceAlsa::MidiInputDeviceAlsa(std::map<String,DeviceCreationParameter*> Parameters, void* pSampler) : MidiInputDevice(Parameters, pSampler), Thread(true, true, 1, -1) { if (snd_seq_open(&hAlsaSeq, "default", SND_SEQ_OPEN_INPUT, 0) < 0) { throw MidiInputException("Error opening ALSA sequencer"); } this->hAlsaSeqClient = snd_seq_client_id(hAlsaSeq); snd_seq_set_client_name(hAlsaSeq, "LinuxSampler"); AcquirePorts(((DeviceCreationParameterInt*)Parameters["PORTS"])->ValueAsInt()); if (((DeviceCreationParameterBool*)Parameters["ACTIVE"])->ValueAsBool()) { Listen(); } }
static void init_seq(void) { int err; /* open sequencer */ err = snd_seq_open(&seq, "default", SND_SEQ_OPEN_DUPLEX, 0); check_snd("open sequencer", err); /* set our client's name */ err = snd_seq_set_client_name(seq, "aseqdump"); check_snd("set client name", err); }
int bx_sound_linux_c::alsa_seq_open(const char *alsadev) { char *mididev, *ptr; int client, port, ret = 0; int length = strlen(alsadev) + 1; mididev = new char[length]; if (mididev == NULL) return BX_SOUNDLOW_ERR; strcpy(mididev, alsadev); ptr = strtok(mididev, ":"); if (ptr == NULL) { BX_ERROR(("ALSA sequencer setup: missing client parameters")); return BX_SOUNDLOW_ERR; } client = atoi(ptr); ptr = strtok(NULL, ":"); if (ptr == NULL) { BX_ERROR(("ALSA sequencer setup: missing port parameter")); return BX_SOUNDLOW_ERR; } port = atoi(ptr); delete(mididev); if (snd_seq_open(&alsa_seq.handle, "default", SND_SEQ_OPEN_OUTPUT, 0) < 0) { BX_ERROR(("Couldn't open ALSA sequencer for midi output")); return BX_SOUNDLOW_ERR; } ret = snd_seq_create_simple_port(alsa_seq.handle, NULL, SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE | SND_SEQ_PORT_CAP_READ, SND_SEQ_PORT_TYPE_MIDI_GENERIC); if (ret < 0) { BX_ERROR(("ALSA sequencer: error creating port %s", snd_strerror(errno))); } else { alsa_seq.source_port = ret; ret = snd_seq_connect_to(alsa_seq.handle, alsa_seq.source_port, client, port); if (ret < 0) { BX_ERROR(("ALSA sequencer: could not connect to port %d:%d", client, port)); } } if (ret < 0) { snd_seq_close(alsa_seq.handle); return BX_SOUNDLOW_ERR; } else { return BX_SOUNDLOW_OK; } }
int ALSADrv_MIDI_Init(midifuncs *funcs) { int result; ALSADrv_MIDI_Shutdown(); memset(funcs, 0, sizeof(midifuncs)); result = snd_seq_open(&seq, "default", SND_SEQ_OPEN_DUPLEX, 0); if (result < 0) { fprintf(stderr, "ALSA snd_seq_open err %d\n", result); ErrorCode = ALSAErr_SeqOpen; return ALSAErr_Error; } seq_port = snd_seq_create_simple_port(seq, "output", SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_WRITE, SND_SEQ_PORT_TYPE_APPLICATION); if (seq_port < 0) { ALSADrv_MIDI_Shutdown(); fprintf(stderr, "ALSA snd_seq_create_simple_port err %d\n", seq_port); ErrorCode = ALSAErr_CreateSimplePort; return ALSAErr_Error; } snd_seq_set_client_name(seq, "JFAudioLib application"); seq_queue = snd_seq_alloc_queue(seq); if (seq_queue < 0) { ALSADrv_MIDI_Shutdown(); fprintf(stderr, "ALSA snd_seq_alloc_queue err %d\n", seq_queue); ErrorCode = ALSAErr_AllocQueue; return ALSAErr_Error; } result = snd_seq_connect_to(seq, seq_port, 128, 0); if (result < 0) { ALSADrv_MIDI_Shutdown(); fprintf(stderr, "ALSA snd_seq_connect_to err %d\n", result); ErrorCode = ALSAErr_ConnectTo; return ALSAErr_Error; } funcs->NoteOff = Func_NoteOff; funcs->NoteOn = Func_NoteOn; funcs->PolyAftertouch = Func_PolyAftertouch; funcs->ControlChange = Func_ControlChange; funcs->ProgramChange = Func_ProgramChange; funcs->ChannelAftertouch = Func_ChannelAftertouch; funcs->PitchBend = Func_PitchBend; return ALSAErr_Ok; }
static void midi_connect_sequencer() { int err; err = snd_seq_open(&midi_sequencer, "default", SND_SEQ_OPEN_OUTPUT, 0); assert (err >= 0); snd_seq_set_client_name(midi_sequencer, "midimatch"); snd_seq_create_simple_port(midi_sequencer, "matched midi data", SND_SEQ_PORT_CAP_READ|SND_SEQ_PORT_CAP_SUBS_READ, SND_SEQ_PORT_TYPE_MIDI_GENERIC); snd_seq_connect_to(midi_sequencer, 0, 128, 0); }
/* * Allocate and initialize the MIDI interfaces. */ snd_seq_t *sequencer_new(int *in_port_ptr, int *out_port_ptr, char *port_name) { snd_seq_t *seq_handle; char input_name[255]; char output_name[255]; int mode = 0; sprintf(input_name, "%s - In", port_name); sprintf(output_name, "%s - Out", port_name); if (NULL != in_port_ptr) { mode = mode | SND_SEQ_OPEN_INPUT; } if (NULL != out_port_ptr) { mode = mode | SND_SEQ_OPEN_OUTPUT; } /* * Open an ALSA MIDI input and output ports. */ if (snd_seq_open(&seq_handle, "default", SND_SEQ_OPEN_DUPLEX, 0) < 0) { error("Error opening ALSA sequencer for '%s'.", port_name); } snd_seq_set_client_name(seq_handle, port_name); if (in_port_ptr) { *in_port_ptr = snd_seq_create_simple_port(seq_handle, input_name, SND_SEQ_PORT_CAP_WRITE | SND_SEQ_PORT_CAP_SUBS_WRITE, SND_SEQ_PORT_TYPE_APPLICATION); if (*in_port_ptr < 0) { error("Error creating sequencer input port for '%s'.", port_name); } } if (out_port_ptr) { *out_port_ptr = snd_seq_create_simple_port(seq_handle, output_name, SND_SEQ_PORT_CAP_READ | SND_SEQ_PORT_CAP_SUBS_READ, SND_SEQ_PORT_TYPE_APPLICATION); if (*out_port_ptr < 0) { error("Error creating sequencer output port for '%s'.", port_name); } } return seq_handle; }
void midi_open(void) { snd_seq_open(&seq_handle, "default", SND_SEQ_OPEN_INPUT, 0); snd_seq_set_client_name(seq_handle, "LightOrgan8"); in_port = snd_seq_create_simple_port(seq_handle, "listen:in", SND_SEQ_PORT_CAP_WRITE|SND_SEQ_PORT_CAP_SUBS_WRITE, SND_SEQ_PORT_TYPE_APPLICATION); if( snd_seq_connect_from(seq_handle, in_port, THRUPORTCLIENT, THRUPORTPORT) == -1) { perror("Can't connect to thru port"); exit(-1); } }
MidiAlsaSeq::MidiAlsaSeq() : MidiClient(), m_seqMutex(), m_seqHandle( NULL ), m_queueID( -1 ), m_quit( false ), m_portListUpdateTimer( this ) { int err; if( ( err = snd_seq_open( &m_seqHandle, probeDevice().toLatin1().constData(), SND_SEQ_OPEN_DUPLEX, 0 ) ) < 0 ) { fprintf( stderr, "cannot open sequencer: %s\n", snd_strerror( err ) ); return; } snd_seq_set_client_name( m_seqHandle, "LMMS" ); m_queueID = snd_seq_alloc_queue( m_seqHandle ); snd_seq_queue_tempo_t * tempo; snd_seq_queue_tempo_malloc( &tempo ); snd_seq_queue_tempo_set_tempo( tempo, 6000000 / Engine::getSong()->getTempo() ); snd_seq_queue_tempo_set_ppq( tempo, 16 ); snd_seq_set_queue_tempo( m_seqHandle, m_queueID, tempo ); snd_seq_queue_tempo_free( tempo ); snd_seq_start_queue( m_seqHandle, m_queueID, NULL ); changeQueueTempo( Engine::getSong()->getTempo() ); connect( Engine::getSong(), SIGNAL( tempoChanged( bpm_t ) ), this, SLOT( changeQueueTempo( bpm_t ) ) ); // initial list-update updatePortList(); connect( &m_portListUpdateTimer, SIGNAL( timeout() ), this, SLOT( updatePortList() ) ); // we check for port-changes every second m_portListUpdateTimer.start( 1000 ); // use a pipe to detect shutdown if( pipe( m_pipe ) == -1 ) { perror( __FILE__ ": pipe" ); } start( QThread::IdlePriority ); }