本文整理汇总了C++中RtMidiIn::getPortCount方法的典型用法代码示例。如果您正苦于以下问题:C++ RtMidiIn::getPortCount方法的具体用法?C++ RtMidiIn::getPortCount怎么用?C++ RtMidiIn::getPortCount使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RtMidiIn
的用法示例。
在下文中一共展示了RtMidiIn::getPortCount方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getPortList
bool MidiInRt::getPortList(QVector<QString> &ports)
{
RtMidiIn *midiin = lazyInstance();
#if (QT_VERSION < 0x050000) && defined(_WIN32)
RtMidi::Api api = midiin->getCurrentApi();
#endif
m_errorSignaled = false;
unsigned count = midiin->getPortCount();
if(m_errorSignaled)
return false;
ports.resize(count);
for(unsigned i = 0; i < count; ++i)
{
m_errorSignaled = false;
#if (QT_VERSION < 0x050000) && defined(_WIN32)
if(api == RtMidi::WINDOWS_MM)
{
MIDIINCAPSA deviceCaps;
midiInGetDevCapsA(i, &deviceCaps, sizeof(MIDIINCAPSA));
ports[i] = QString::fromLocal8Bit(deviceCaps.szPname);
}
else
#endif
{
std::string name = midiin->getPortName(i);
if(m_errorSignaled)
return false;
ports[i] = QString::fromStdString(name);
}
}
return true;
}
示例2: probeMidiIn
//-----------------------------------------------------------------------------
// name: probeMidiIn()
// desc: ...
//-----------------------------------------------------------------------------
void probeMidiIn()
{
RtMidiIn * min = NULL;
try {
min = new RtMidiIn;;
} catch( RtMidiError & err ) {
EM_error2b( 0, "%s", err.getMessage().c_str() );
return;
}
// get num
t_CKUINT num = min->getPortCount();
EM_error2b( 0, "------( chuck -- %i MIDI inputs )------", num );
EM_reset_msg();
std::string s;
for( t_CKUINT i = 0; i < num; i++ )
{
try { s = min->getPortName( i ); }
catch( RtMidiError & err )
{ err.printMessage(); return; }
EM_error2b( 0, " [%i] : \"%s\"", i, s.c_str() );
EM_reset_msg();
}
}
示例3: 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;
}
示例4: showEvent
////////////////////////////////////////////////////////////////////////////////
// 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;
}
示例5: open
t_CKBOOL MidiInManager::open( MidiIn * min, Chuck_VM * vm, const std::string & name )
{
t_CKINT device_num = -1;
try
{
RtMidiIn * rtmin = new RtMidiIn;
t_CKINT count = rtmin->getPortCount();
for(t_CKINT i = 0; i < count; i++)
{
std::string port_name = rtmin->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 = rtmin->getPortName( i );
if( port_name.find( name ) != std::string::npos )
{
device_num = i;
break;
}
}
}
}
catch( RtMidiError & err )
{
if( !min->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( min, vm, device_num );
return result;
}
示例6: 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;
}
示例7: getDeviceInfo
// ******************************************
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: setup
void Midi::setup(){
RtMidiIn *channels = new RtMidiIn();
int port_number = channels->getPortCount();
delete channels;
if(port_number>0){
active = true;
for(int i = 0; i<port_number; i++){
RtMidiIn *temp = new RtMidiIn();
devices.push_back(temp);
devices.at(i)->openPort(i);
devices.at(i)->ignoreTypes(false,false,false);
}
}
}
示例9: refreshPorts
/**
* Get the list of available ports.
* Can be called repeatedly to regenerate the list if a MIDI device is plugged in or unplugged.
*/
void refreshPorts() {
char cPortName[MAX_STR_SIZE];
inPortMap.clear();
outPortMap.clear();
if(midiin) {
numInPorts = midiin->getPortCount();
for ( int i=0; i<numInPorts; i++ ) {
try {
std::string portName = midiin->getPortName(i);
// CME Xkey reports its name as "Xkey ", which was a hassle to deal with in a Max patch, so auto-trim the names.
portName = trim(portName);
strncpy(cPortName, portName.c_str(), MAX_STR_SIZE);
cPortName[MAX_STR_SIZE - 1] = NULL;
inPortMap[gensym(cPortName)] = i;
}
catch ( RtMidiError &error ) {
printError("Error getting MIDI input port name", error);
}
}
}
if(midiout) {
numOutPorts = midiout->getPortCount();
for ( int i=0; i<numOutPorts; i++ ) {
try {
std::string portName = midiout->getPortName(i);
// CME Xkey reports its name as "Xkey ", which was a hassle to deal with in a Max patch, so auto-trim the names.
portName = trim(portName);
strncpy(cPortName, portName.c_str(), MAX_STR_SIZE);
cPortName[MAX_STR_SIZE - 1] = NULL;
outPortMap[gensym(cPortName)] = i;
}
catch (RtMidiError &error) {
printError("Error getting MIDI output port name", error);
}
}
}
}
示例10: catch
QList<MidiDevice::Description> MidiDevice::enumerateInputDevices()
{
RtMidiIn midiIn;
QList<MidiDevice::Description> devs;
int n = midiIn.getPortCount();
for (int i = 0; i < n; i++) {
Description desc;
desc.number = i;
desc.type = Type_Input;
try {
desc.name = QString::fromStdString(midiIn.getPortName(i));
devs.append(desc);
} catch (RtMidiError &err) {
Q_UNUSED(err);
}
}
return devs;
}
示例11: p
vector<pair<int, string> > MidiInputController::availableMidiDevices() {
RtMidiIn rtMidiIn;
vector<pair<int, string> > deviceList;
try {
int numDevices = rtMidiIn.getPortCount();
for(int i = 0; i < numDevices; i++) {
pair<int, string> p(i, rtMidiIn.getPortName(i));
deviceList.push_back(p);
}
}
catch(...) {
deviceList.clear();
}
return deviceList;
}
示例12: catch
/* returns 0 on failure */
int
start_midi(int port)
{
if(midi.getPortCount() < 1) {
std::cout << "No MIDI ports available!\n";
return 0;
}
try {
midi.openPort(port);
} catch(RtError &error) {
return 0;
}
// don't ignore sysex, timing, or active sensing messages
midi.ignoreTypes(false, false, false);
return 1;
}
示例13: rtMidiIn_getDeviceNames
static VALUE rtMidiIn_getDeviceNames(VALUE self)
{
RtMidiIn *device;
Data_Get_Struct(self, RtMidiIn, device);
VALUE devices = rb_ary_new();
int numDevices = device->getPortCount();
for(int x = 0; x < numDevices; x++)
{
rb_warn("trying port %i out of %x\n", x, numDevices);
try {
std::string portName = device->getPortName(x);
rb_ary_push(devices, rb_str_new2(portName.c_str()));
}
catch(RtError &error)
{
rb_warn("could not get device name for port %i\n", x);
return Qnil;
}
}
return devices;
}
示例14: rtMidiIn_getNumDevices
static VALUE rtMidiIn_getNumDevices(VALUE self)
{
RtMidiIn *device;
Data_Get_Struct(self, RtMidiIn, device);
return INT2NUM(device->getPortCount());
}
示例15: 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 );
//.........这里部分代码省略.........