本文整理汇总了C++中RtMidiIn::setCallback方法的典型用法代码示例。如果您正苦于以下问题:C++ RtMidiIn::setCallback方法的具体用法?C++ RtMidiIn::setCallback怎么用?C++ RtMidiIn::setCallback使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RtMidiIn
的用法示例。
在下文中一共展示了RtMidiIn::setCallback方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: enablePort
bool MidiInputController::enablePort(int portNumber) {
if(portNumber < 0)
return false;
try {
MidiInputCallback *callback = new MidiInputCallback;
RtMidiIn *rtMidiIn = new RtMidiIn;
cout << "Enabling MIDI port " << portNumber << " (" << rtMidiIn->getPortName(portNumber) << ")\n";
rtMidiIn->openPort(portNumber); // Open the port
rtMidiIn->ignoreTypes(true, true, true); // Ignore sysex, timing, active sensing
callback->controller = this;
callback->midiIn = rtMidiIn;
callback->inputNumber = portNumber;
rtMidiIn->setCallback(MidiInputController::rtMidiStaticCallback, callback);
activePorts_[portNumber] = callback;
}
catch(...) {
return false;
}
return true;
}
示例2: open
t_CKBOOL MidiInManager::open( MidiIn * min, t_CKINT device_num )
{
// see if port not already open
if( device_num >= (t_CKINT)the_mins.capacity() || !the_mins[device_num] )
{
// allocate the buffer
CBufferAdvance * cbuf = new CBufferAdvance;
if( !cbuf->initialize( BUFFER_SIZE, sizeof(MidiMsg) ) )
{
if( !min->m_suppress_output )
EM_error2( 0, "MidiIn: couldn't allocate CBuffer for port %i...", device_num );
delete cbuf;
return FALSE;
}
// allocate
RtMidiIn * rtmin = new RtMidiIn;
try {
rtmin->openPort( device_num );
rtmin->setCallback( cb_midi_input, cbuf );
} catch( RtError & err ) {
if( !min->m_suppress_output )
{
// print it
EM_error2( 0, "MidiIn: 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() );
}
delete cbuf;
return FALSE;
}
// resize?
if( device_num >= (t_CKINT)the_mins.capacity() )
{
t_CKINT size = the_mins.capacity() * 2;
if( device_num >= size ) size = device_num + 1;
the_mins.resize( size );
the_bufs.resize( size );
}
// put cbuf and rtmin in vector for future generations
the_mins[device_num] = rtmin;
the_bufs[device_num] = cbuf;
}
// set min
min->min = the_mins[device_num];
// found
min->m_buffer = the_bufs[device_num];
// get an index into your (you are min here) own buffer,
// and a free ticket to your own workshop
min->m_read_index = min->m_buffer->join( (Chuck_Event *)min->SELF );
min->m_device_num = (t_CKUINT)device_num;
// done
return TRUE;
}
示例3: main
int main(int argc, char** argv)
{
if (argc != 2) {
printf("Usage: synth file.sf2\n");
exit(0);
}
LightFluidSynth *usynth;
usynth = new LightFluidSynth();
usynth->loadSF2(argv[1]);
// usynth->loadSF2("tim.sf2");
RtMidiIn *midiIn = new RtMidiIn();
if (midiIn->getPortCount() == 0) {
std::cout << "No MIDI ports available!\n";
}
midiIn->openPort(0);
midiIn->setCallback( &midiCallback, (void *)usynth );
midiIn->ignoreTypes( false, false, false );
// RtAudio dac(RtAudio::LINUX_PULSE);
RtAudio dac;
RtAudio::StreamParameters rtParams;
// Determine the number of devices available
unsigned int devices = dac.getDeviceCount();
// Scan through devices for various capabilities
RtAudio::DeviceInfo info;
for ( unsigned int i = 0; i < devices; i++ ) {
info = dac.getDeviceInfo( i );
if ( info.probed == true ) {
std::cout << "device " << " = " << info.name;
std::cout << ": maximum output channels = " << info.outputChannels << "\n";
}
}
// rtParams.deviceId = 3;
rtParams.deviceId = dac.getDefaultOutputDevice();
rtParams.nChannels = 2;
unsigned int bufferFrames = FRAME_SIZE;
RtAudio::StreamOptions options;
options.flags = RTAUDIO_SCHEDULE_REALTIME;
dac.openStream( &rtParams, NULL, AUDIO_FORMAT, SAMPLE_RATE, &bufferFrames, &audioCallback, (void *)usynth, &options );
dac.startStream();
printf("\n\nPress Enter to stop\n\n");
cin.get();
dac.stopStream();
delete(usynth);
return 0;
}
示例4: RtMidiIn
RtMidiIn *MidiInRt::lazyInstance()
{
RtMidiIn *midiin = m_midiin;
if(!midiin) {
unsigned bufferSize = 1024;
midiin = m_midiin = new RtMidiIn(
RtMidi::UNSPECIFIED, defaultClientName().toStdString(), bufferSize);
midiin->setCallback(&onReceive, this);
midiin->setErrorCallback(&onError, this);
}
return midiin;
}
示例5: setupMidi
void Cursynth::setupMidi() {
RtMidiIn* midi_in = new RtMidiIn();
if (midi_in->getPortCount() <= 0) {
std::cout << "No midi devices found.\n";
}
// Setup MIDI callbacks for every MIDI device.
// TODO: Have a menu for only enabling some MIDI devices.
for (unsigned int i = 0; i < midi_in->getPortCount(); ++i) {
RtMidiIn* device = new RtMidiIn();
device->openPort(i);
device->setCallback(&midiCallback, (void*)this);
midi_ins_.push_back(device);
}
delete midi_in;
}
示例6: rtmidi_in_set_callback
void rtmidi_in_set_callback (RtMidiInPtr device, RtMidiCCallback callback, void *userData)
{
device->data = (void*) new CallbackProxyUserData (callback, userData);
#if defined(__NO_EXCEPTIONS__)
RtMidiIn* rtm = (RtMidiIn*) device->ptr;
rtm->resetError();
rtm->setCallback (callback_proxy, device->data);
if (rtm->isError()) {
device->ok = false;
device->msg = rtm->getError().what ();
delete (CallbackProxyUserData*) device->data;
device->data = 0;
}
#else
try {
((RtMidiIn*) device->ptr)->setCallback (callback_proxy, device->data);
} catch (const RtMidiError & err) {
device->ok = false;
device->msg = err.what ();
delete (CallbackProxyUserData*) device->data;
device->data = 0;
}
#endif
}
示例7: main
//-----------------------------------------------------------------------------
// name: main()
// desc: entry point
//-----------------------------------------------------------------------------
int main( int argc, char ** argv )
{
RtMidiIn *midiin = new RtMidiIn();
// Check available ports.
unsigned int nPorts = midiin->getPortCount();
if ( nPorts == 0 ) {
std::cout << "No ports available!\n";
//goto cleanup;
}
midiin->openPort( 0 );
// Set our callback function. This should be done immediately after
// opening the port to avoid having incoming messages written to the
// queue.
midiin->setCallback( &mycallback );
// Don't ignore sysex, timing, or active sensing messages.
midiin->ignoreTypes( false, false, false );
std::cout << "\nReading MIDI input ... press <enter> to quit.\n";
char input;
std::cin.get(input);
// instantiate RtAudio object
RtAudio audio;
// variables
unsigned int bufferBytes = 0;
// frame size
unsigned int numFrames = 512;
// check for audio devices
if( audio.getDeviceCount() < 1 )
{
// nopes
cout << "no audio devices found!" << endl;
exit( 1 );
}
// let RtAudio print messages to stderr.
audio.showWarnings( true );
// set input and output parameters
RtAudio::StreamParameters iParams, oParams;
iParams.deviceId = audio.getDefaultInputDevice();
iParams.nChannels = MY_CHANNELS;
iParams.firstChannel = 0;
oParams.deviceId = audio.getDefaultOutputDevice();
oParams.nChannels = MY_CHANNELS;
oParams.firstChannel = 0;
// create stream options
RtAudio::StreamOptions options;
// go for it
try {
// open a stream
audio.openStream( &oParams, &iParams, MY_FORMAT, MY_SRATE, &numFrames, &callme, NULL, &options );
}
catch( RtError& e )
{
// error!
cout << e.getMessage() << endl;
exit( 1 );
}
// compute
bufferBytes = numFrames * MY_CHANNELS * sizeof(SAMPLE);
// test RtAudio functionality for reporting latency.
cout << "stream latency: " << audio.getStreamLatency() << " frames" << endl;
for( int i = 0; i < MY_NUMSTRINGS; i++ )
{
// intialize
g_ks[i].init( MY_SRATE*2, 440, MY_SRATE );
}
// go for it
try {
// start stream
audio.startStream();
char input;
std::cout << "Press any key to quit ";
std::cin.get(input);
// stop the stream.
audio.stopStream();
}
catch( RtError& e )
{
// print error message
//.........这里部分代码省略.........
示例8: rtmidi_in_setcallback
value rtmidi_in_setcallback(value obj, value func) {
RtMidiIn *midiin = (RtMidiIn *)(intptr_t)val_float(obj);
callback_root = new AutoGCRoot(func);
midiin->setCallback(&_rtmidi_in_callback);
return alloc_null();
}
示例9: main
int main (int argc, char ** argv)
{
//parse tempo
if (argc>2)
{
cerr<<"Error in arguments\n";
printHelp();
exit(1);
}
else if (argc==2)
{
g_tempo = atoi(argv[1]);
if (g_tempo<40 && g_tempo>200)
{
cerr<<"Tempo out of bounds!\n";
printHelp();
exit(1);
}
tempoChange();
}
// set up fluid synth stuff
// TODO: error checking!!!!
g_settings = new_fluid_settings();
g_synth = new_fluid_synth( g_settings );
g_metronome = new_fluid_synth( g_settings );
//fluid_player_t* player;
//player = new_fluid_player(g_synth);
//fluid_player_add(player, "backing.mid");
//fluid_player_play(player);
if (fluid_synth_sfload(g_synth, "piano.sf2", 1) == -1)
{
cerr << "Error loading sound font" << endl;
exit(1);
}
if (fluid_synth_sfload(g_metronome, "drum.sf2", 1) == -1)
{
cerr << "Error loading sound font" << endl;
exit(1);
}
// RtAudio config + init
// pointer to RtAudio object
RtMidiIn * midiin = NULL;
RtAudio * audio = NULL;
unsigned int bufferSize = 512;//g_sixteenth/100;
// MIDI config + init
try
{
midiin = new RtMidiIn();
}
catch( RtError & err ) {
err.printMessage();
// goto cleanup;
}
// Check available ports.
if ( midiin->getPortCount() == 0 )
{
std::cout << "No ports available!\n";
// goto cleanup;
}
// use the first available port
if ( midiin->getPortCount() > 2)
midiin->openPort( 1 );
else
midiin->openPort( 0 );
// set midi callback
midiin->setCallback( &midi_callback );
// Don't ignore sysex, timing, or active sensing messages.
midiin->ignoreTypes( false, false, false );
// create the object
try
{
audio = new RtAudio();
cerr << "buffer size: " << bufferSize << endl;
}
catch( RtError & err ) {
err.printMessage();
exit(1);
}
if( audio->getDeviceCount() < 1 )
{
// nopes
cout << "no audio devices found!" << endl;
exit( 1 );
//.........这里部分代码省略.........