/* * sndpgmchg.cpp * Sends MIDI bank change and program change ALSA messages * * Drumstick library documentation: * http://drumstick.sourceforge.net/docs/ * * usage: * sndpgmchg CHAN CC0 CC32 PGM * * CHAN: MIDI channel (0..15) * CC0: bank change, MSB (0..127) * CC32: bank change, LSB (0..127) * PGM: program change (0..127) * * example: sndpgmchg 0 1 0 2 * * by: Pedro Lopez-Cabanillas * This code is in the public domain */ #include #include #include #include #include int main (int argc, char **argv) { QCoreApplication app(argc, argv); QTextStream cout (stdout, QIODevice::WriteOnly); int chan = 0, cc0 = 0, cc32 = 0, pgm = 0; // get the command line arguments QStringList arglist = app.arguments (); if (arglist.count () < 5) { cout << "Usage: " << arglist.at (0) << " CHAN CC0 CC32 PGM" << endl; return 1; } chan = arglist.at (1).toInt (); cc0 = arglist.at (2).toInt (); cc32 = arglist.at (3).toInt (); pgm = arglist.at (4).toInt (); // create a client object on the heap drumstick::MidiClient *client = new drumstick::MidiClient; client->open (); client->setClientName ("sndpgmchg"); // create the port drumstick::MidiPort *port = client->createPort (); port->setPortName ("output port"); port->setCapability (SND_SEQ_PORT_CAP_READ); port->setPortType (SND_SEQ_PORT_TYPE_MIDI_GENERIC); // subscribe the output port to some destination(s) port->subscribeTo ("KMidimon:0"); // client-name:port-id // port->subscribeTo ("129:0"); // client-id:port-id // create a list of sequencer events QList lst; lst << new drumstick::ControllerEvent (chan, 0, cc0); // bank change, MSB lst << new drumstick::ControllerEvent (chan, 32, cc32); // bank change, LSB lst << new drumstick::ProgramChangeEvent (chan, pgm); // program change // send events foreach (drumstick::SequencerEvent *ev, lst) { ev->setSource (port->getPortId ()); ev->setSubscribers (); // deliver to all the connected ports ev->setDirect (); // not scheduled, deliver immediately client->outputDirect (ev); // not buffered } // close and clean client->close (); delete client; return 0; }