本文整理汇总了C++中RtMidiOut类的典型用法代码示例。如果您正苦于以下问题:C++ RtMidiOut类的具体用法?C++ RtMidiOut怎么用?C++ RtMidiOut使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RtMidiOut类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: openOutputDevice
FREObject openOutputDevice(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
int index = 0;
FREGetObjectAsInt32(argv[0],&index);
//printf("Native MIDI :: open output device %i\n",index);
int pointer = -1;
try {
RtMidiOut* out = new RtMidiOut();
out->openPort(index);
openMidiOut.push_back(out);
pointer = (int)out;
//printf("Open midi pointer : %i\n",pointer);
// Don't ignore sysex, timing, or active sensing messages.
}
catch ( RtMidiError &error ) {
error.printMessage();
}
FREObject result;
FRENewObjectFromInt32(pointer,&result);
return result;
}
示例2: main
int main()
{
// Create an api map.
std::map<int, std::string> apiMap;
apiMap[RtMidi::MACOSX_CORE] = "OS-X CoreMidi";
apiMap[RtMidi::WINDOWS_MM] = "Windows MultiMedia";
apiMap[RtMidi::UNIX_JACK] = "Jack Client";
apiMap[RtMidi::LINUX_ALSA] = "Linux ALSA";
apiMap[RtMidi::RTMIDI_DUMMY] = "RtMidi Dummy";
std::vector< RtMidi::Api > apis;
RtMidi :: getCompiledApi( apis );
std::cout << "\nCompiled APIs:\n";
for ( unsigned int i=0; i<apis.size(); i++ )
std::cout << " " << apiMap[ apis[i] ] << std::endl;
RtMidiIn *midiin = 0;
RtMidiOut *midiout = 0;
try {
// RtMidiIn constructor ... exception possible
midiin = new RtMidiIn();
std::cout << "\nCurrent input API: " << apiMap[ midiin->getCurrentApi() ] << std::endl;
// Check inputs.
unsigned int nPorts = midiin->getPortCount();
std::cout << "\nThere are " << nPorts << " MIDI input sources available.\n";
for ( unsigned i=0; i<nPorts; i++ ) {
std::string portName = midiin->getPortName(i);
std::cout << " Input Port #" << i+1 << ": " << portName << '\n';
}
// RtMidiOut constructor ... exception possible
midiout = new RtMidiOut();
std::cout << "\nCurrent output API: " << apiMap[ midiout->getCurrentApi() ] << std::endl;
// Check outputs.
nPorts = midiout->getPortCount();
std::cout << "\nThere are " << nPorts << " MIDI output ports available.\n";
for ( unsigned i=0; i<nPorts; i++ ) {
std::string portName = midiout->getPortName(i);
std::cout << " Output Port #" << i+1 << ": " << portName << std::endl;
}
std::cout << std::endl;
} catch ( RtMidiError &error ) {
error.printMessage();
}
delete midiin;
delete midiout;
return 0;
}
示例3: rtmidi_out_send_message
int rtmidi_out_send_message (RtMidiOutPtr device, const unsigned char *message, int length)
{
#if defined(__NO_EXCEPTIONS__)
RtMidiOut* rtm = (RtMidiOut*) device->ptr;
rtm->resetError();
rtm->sendMessage (message, length);
if (rtm->isError()) {
device->ok = false;
device->msg = rtm->getError().what ();
return -1;
}
return 0;
#else
try {
((RtMidiOut*) device->ptr)->sendMessage (message, length);
return 0;
}
catch (const RtMidiError & err) {
device->ok = false;
device->msg = err.what ();
return -1;
}
catch (...) {
device->ok = false;
device->msg = "Unknown error";
return -1;
}
#endif
}
示例4: sendMIDIMessage
FREObject sendMIDIMessage(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
int pointer = 0;
int status = 0;
int data1 = 0;
int data2 = 0;
FREGetObjectAsInt32(argv[0],&pointer);
FREGetObjectAsInt32(argv[1],&status);
FREGetObjectAsInt32(argv[2],&data1);
FREGetObjectAsInt32(argv[3],&data2);
RtMidiOut* out = (RtMidiOut *)pointer;
//printf("Send Message : %i %i %i %i\n",out,status,data1,data2);
outMessage[0] = (unsigned char)status;
outMessage[1] = (unsigned char)data1;
outMessage[2] = (unsigned char)data2;
bool sendResult = false;
try
{
if(out->isPortOpen()) out->sendMessage(&outMessage);
}catch(std::exception e)
{
printf("Error sending message : %s\n",e.what());
}
FREObject result;
FRENewObjectFromBool(sendResult,&result);
return result;
}
示例5: name
////////////////////////////////////////////////////////////////////////////////
// SetupDialog::showEvent()
////////////////////////////////////////////////////////////////////////////////
///\brief Message handler for the window show event.
///\param [in] e: Description of the event.
////////////////////////////////////////////////////////////////////////////////
void SetupDialog::showEvent(QShowEvent* /*e*/)
{
// Lock UI:
blocked = true;
// Get MIDI in properties:
RtMidiIn midiIn;
unsigned int portCnt = midiIn.getPortCount();
if (portCnt > 0)
{
int selItem = -1;
// Loop through MIDI ports:
for (unsigned int i = 0; i < portCnt; i++)
{
// Get name of the port:
QString name(midiIn.getPortName(i).c_str());
// Does this match the currently selected option?
if (name == inputName)
selItem = i;
// Add item to the combo box:
ui->inputComboBox->addItem(name);
}
// Select current item, if any:
ui->inputComboBox->setCurrentIndex(selItem);
}
// Get MIDI out properties:
RtMidiOut midiOut;
portCnt = midiOut.getPortCount();
if (portCnt > 0)
{
int selItem = -1;
// Loop through MIDI ports:
for (unsigned int i = 0; i < portCnt; i++)
{
// Get name of the port:
QString name(midiOut.getPortName(i).c_str());
// Does this match the currently selected option?
if (name == outputName)
selItem = i;
// Add item to the combo box:
ui->outputComboBox->addItem(name);
}
// Select current item, if any:
ui->outputComboBox->setCurrentIndex(selItem);
}
// Unlock UI:
blocked = false;
}
示例6: open
t_CKBOOL MidiOutManager::open( MidiOut * mout, const std::string & name )
{
t_CKINT device_num = -1;
try
{
RtMidiOut * rtmout = new RtMidiOut;
t_CKINT count = rtmout->getPortCount();
for(t_CKINT i = 0; i < count; i++)
{
std::string port_name = rtmout->getPortName( i );
if( port_name == name )
{
device_num = i;
break;
}
}
if( device_num == -1 )
{
// search by substring
for(t_CKINT i = 0; i < count; i++)
{
std::string port_name = rtmout->getPortName( i );
if( port_name.find( name ) != std::string::npos )
{
device_num = i;
break;
}
}
}
}
catch( RtMidiError & err )
{
if( !mout->m_suppress_output )
{
// print it
EM_error2( 0, "MidiOut: error locating MIDI port named %s", name.c_str() );
err.getMessage();
// const char * e = err.getMessage().c_str();
// EM_error2( 0, "...(%s)", err.getMessage().c_str() );
}
return FALSE;
}
if(device_num == -1)
{
EM_error2( 0, "MidiOut: error locating MIDI port named %s", name.c_str() );
return FALSE;
}
t_CKBOOL result = open( mout, device_num );
return result;
}
示例7: RtMidiIn
// ******************************************
void shruthiEditorSettings::getDeviceInfo() {
// ******************************************
RtMidiIn *midiin = 0;
RtMidiOut *midiout = 0;
QString name;
// Input ports:
try {
midiin = new RtMidiIn();
}
catch ( RtError &error ) {
error.printMessage();
exit( EXIT_FAILURE );
}
unsigned int numdev = midiin->getPortCount();
std::cout << numdev << " midi input devices found.\n";
for (unsigned int i=0; i < numdev; i++) {
try {
name = QString::fromStdString(midiin->getPortName(i));
}
catch ( RtError &error ) {
error.printMessage();
goto cleanup;
}
midi_input_device->addItem(name,i);
}
// Output ports:
try {
midiout = new RtMidiOut();
}
catch ( RtError &error ) {
error.printMessage();
exit( EXIT_FAILURE );
}
numdev = midiout->getPortCount();
std::cout << numdev << " midi output devices found.\n";
for (unsigned int i=0; i < numdev; i++) {
try {
name = QString::fromStdString(midiout->getPortName(i));
}
catch ( RtError &error ) {
error.printMessage();
goto cleanup;
}
midi_output_device->addItem(name,i);
}
cleanup:
delete midiin;
delete midiout;
}
示例8: main
int main(int argc, char* argv[])
{
char filename[] = "doom-e1m1.mid";
RtMidiOut *midiout = new RtMidiOut();
string portName;
nPorts = midiout->getPortCount();
if(argc < 2) {
if ( nPorts == 0 ) cout << "No ports available!\n";
for ( unsigned int i=0; i<nPorts; i++ ) {
try { portName = midiout->getPortName(i); }
catch (RtError &error) {error.printMessage(); }
cout << " Output Port #" << i+1 << ": " << portName << '\n';
}
}else{
int port = atoi(argv[1]);
//midiout->openPort( port );
cout << "Opening midi" << endl;
char *filef = argv[2];
if(argc == 3)
parser.Open(filef);
else
parser.Open(filename);
tickspersecond = ( (parser.bpm / 30.0) * ( parser.tpb));
cout << " Ticks per second: " << tickspersecond << endl;
(void) signal(SIGINT, finish);
tickcount = 0;
Sequencer sequencers[parser.numtracks];
SequencerRunning = true;
for(int i=0;i<parser.numtracks;i++) {
sequencers[i].StartSequencer(i, &parser.mididata.tracks[i], port);
sf::Sleep(0.01f);
}
sf::Sleep(1);
timer.Reset();
while(run) {
timecount = timer.GetElapsedTime();
tickcount += timecount * tickspersecond;
timer.Reset();
//sf::Sleep(0.0001f);
}
}
delete midiout;
finish(0);
return 0;
}
示例9: rtmidi_out_sendmessage
value rtmidi_out_sendmessage(value obj, value msg) {
RtMidiOut *midiout = (RtMidiOut *)(intptr_t)val_float(obj);
std::vector<unsigned char> message;
int size = val_array_size(msg);
for (int i = 0; i < size; ++i) {
message.push_back(val_int(val_array_i(msg, i)));
}
midiout->sendMessage(&message);
return alloc_null();
}
示例10: main
int main()
{
std::vector<unsigned char> message;
RtMidiOut *midiout = new RtMidiOut();
// Check available ports.
unsigned int nPorts = midiout->getPortCount();
if ( nPorts == 0 ) {
std::cout << "No ports available!\n";
goto cleanup;
}
cout<<"sending messages"<<endl;
// Open first available port.
midiout->openPort( 0 );
// Send out a series of MIDI messages.
// Program change: 192, 5
message.push_back( 192 );
message.push_back( 5 );
midiout->sendMessage( &message );
// Control Change: 176, 7, 100 (volume)
message[0] = 176;
message[1] = 7;
message.push_back( 100 );
midiout->sendMessage( &message );
// Note On: 144, 64, 90
message[0] = 144;
message[1] = 64;
message[2] = 90;
midiout->sendMessage( &message );
sleep(1);
message[0] = 144;
message[1] = 64;
message[2] = 90;
midiout->sendMessage( &message );
sleep(3);
cout<<"inside"<<endl;
int bend;
while(1){
cin>>bend;
if (!bend) break;
message[0] = 224;
message[1] = 0;
message[2] = bend;
midiout->sendMessage( &message );
}
// Note Off: 128, 64, 40
message[0] = 128;
message[1] = 64;
message[2] = 40;
midiout->sendMessage( &message );
// Clean up
cleanup:
delete midiout;
}
示例11: closeOutputDevice
FREObject closeOutputDevice(FREContext ctx, void* funcData, uint32_t argc, FREObject argv[])
{
int pointer = 0;
FREGetObjectAsInt32(argv[0],&pointer);
try
{
RtMidiOut *out = (RtMidiOut *)pointer;
if(out->isPortOpen()) out->closePort();
removeDeviceOut(out);
delete out;
}catch(std::exception e)
{
printf("Error closing output device.\n");
}
FREObject result;
FRENewObjectFromBool(true,&result);
return result;
}
示例12: catch
QList<MidiDevice::Description> MidiDevice::enumerateOutputDevices()
{
RtMidiOut midiOut;
QList<MidiDevice::Description> devs;
int n = midiOut.getPortCount();
for (int i = 0; i < n; i++) {
Description desc;
desc.number = i;
desc.type = Type_Output;
try {
desc.name = QString::fromStdString(midiOut.getPortName(i));
devs.append(desc);
} catch (RtMidiError &err) {
Q_UNUSED(err);
}
}
return devs;
return devs;
}
示例13: open
t_CKBOOL MidiOutManager::open( MidiOut * mout, t_CKINT device_num )
{
// see if port not already open
if( device_num >= (t_CKINT)the_mouts.capacity() || !the_mouts[device_num] )
{
// allocate
RtMidiOut * rtmout = new RtMidiOut;
try {
rtmout->openPort( device_num );
} catch( RtError & err ) {
if( !mout->m_suppress_output )
{
// print it
EM_error2( 0, "MidiOut: couldn't open MIDI port %i...", device_num );
err.getMessage();
// const char * e = err.getMessage().c_str();
// EM_error2( 0, "...(%s)", err.getMessage().c_str() );
}
return FALSE;
}
// resize?
if( device_num >= (t_CKINT)the_mouts.capacity() )
{
t_CKINT size = the_mouts.capacity() * 2;
if( device_num >= size ) size = device_num + 1;
the_mouts.resize( size );
}
// put rtmout in vector for future generations
the_mouts[device_num] = rtmout;
}
// found (always) (except when it doesn't get here)
mout->mout = the_mouts[device_num];
mout->m_device_num = (t_CKUINT)device_num;
// done
return TRUE;
}
示例14: midiSetup
void ofApp::midiSetup(){
/////////////// MIDI SETUP ////////////////////////////////////////////////////////////////////////////////
// Alterar ofxRtMidiOut.cpp ??
//midiOut.listPorts(); // via instance
int portaEscolhida = 0;
static RtMidiOut s_midiOut;
ofLogVerbose("MIDI") << "ofxMidiOut: " << s_midiOut.getPortCount() << " ports available";
for(unsigned int i = 0; i < s_midiOut.getPortCount(); ++i){
string PortName = s_midiOut.getPortName(i);
PortName.pop_back();
if (PortName.compare(0,3,"MMC")==0){ofLogVerbose("MIDI") << "PORTA MMC: " << i;portaEscolhida = i;};
ofLogVerbose("MIDI") << "ofxMidiOut: " << i << ": " << PortName;
}
// connect
if (midiOut.openPort(portaEscolhida)) // by number // Gera LOG
{
ofLogVerbose("MIDI") << "MIDI open: true";
} else {
ofLogVerbose("MIDI") << "MIDI open: false";
ofApp::exit();
}
//midiOut.openPort("1"); // by name
//midiOut.openVirtualPort("ofxMidiOut"); // open a virtual port
for (int ii=0; ii<8; ii++){
vol[ii].enable=1;
vol[ii].test=0;
vol[ii].volume=0;
}
vol2_inverse = 0;
ofLogVerbose("SETUP") << "MIDI inicializado";
/////////////// MIDI SETUP ////////////////////////////////////////////////////////////////////////////////
}
示例15: rtmidi_out_create
RtMidiOutPtr rtmidi_out_create (enum RtMidiApi api, const char *clientName)
{
RtMidiWrapper* wrp = new RtMidiWrapper;
std::string name = clientName;
#if defined(__NO_EXCEPTIONS__)
RtMidiOut* rOut = new RtMidiOut ((RtMidi::Api) api, name);
if (rOut->isError()) {
wrp->ptr = 0;
wrp->data = 0;
wrp->ok = false;
wrp->msg = rOut->getError().what ();
}
else {
wrp->ptr = (void*) rOut;
wrp->data = 0;
wrp->ok = true;
wrp->msg = "";
}
#else
try {
RtMidiOut* rOut = new RtMidiOut ((RtMidi::Api) api, name);
wrp->ptr = (void*) rOut;
wrp->data = 0;
wrp->ok = true;
wrp->msg = "";
} catch (const RtMidiError & err) {
wrp->ptr = 0;
wrp->data = 0;
wrp->ok = false;
wrp->msg = err.what ();
}
#endif
return wrp;
}