在處理中闡述了一些想法之後,我決定將我的MIDI項目移動到C++以便移植到嵌入式平臺。我決定使用RtMidi庫進行MIDI I/O,但是我有一些麻煩佈置代碼,我想要它。我用C++還不是很棒。將RtMidi對象傳遞給函數(C++)
基本上,我想將RtMidiIn對象和RtMidiOut對象傳遞給我的printMidiPorts函數(代碼與RtMidi捆綁的一些示例代碼相同)。我知道這與將midiin和midiout初始化爲指針有關,但我不完全確定。
這是我的代碼:
#include <stdio.h>
#include <iostream>
#include <string>
#include "rtmidi/RtMidi.h"
using namespace std;
void printMidiPorts(RtMidiIn midiin, RtMidiOut midiout)
{
// Check inputs.
unsigned int nPorts = midiin->getPortCount();
std::cout << "\nThere are " << nPorts << " MIDI input sources available.\n";
std::string portName;
for (unsigned int i=0; i<nPorts; i++) {
try {
portName = midiin->getPortName(i);
}
catch (RtError &error) {
error.printMessage();
goto cleanup;
}
std::cout << " Input Port #" << i+1 << ": " << portName << '\n';
}
// Check outputs.
nPorts = midiout->getPortCount();
std::cout << "\nThere are " << nPorts << " MIDI output ports available.\n";
for (unsigned int i=0; i<nPorts; i++) {
try {
portName = midiout->getPortName(i);
}
catch (RtError &error) {
error.printMessage();
goto cleanup;
}
std::cout << " Output Port #" << i+1 << ": " << portName << '\n';
}
std::cout << '\n';
// Clean up
cleanup:
delete midiin;
delete midiout;
}
int main()
{
RtMidiIn *midiin = 0;
RtMidiOut *midiout = 0;
// RtMidiIn constructor
try {
midiin = new RtMidiIn();
}
catch (RtError &error) {
error.printMessage();
exit(EXIT_FAILURE);
}
// RtMidiOut constructor
try {
midiout = new RtMidiOut();
}
catch (RtError &error) {
error.printMessage();
exit(EXIT_FAILURE);
}
printMidiPorts(midiin, midiout);
return 0;
}
這是我的編譯器輸出:
lightArray.cpp: In function ‘void printMidiPorts(RtMidiIn, RtMidiOut)’:
lightArray.cpp:19: error: base operand of ‘->’ has non-pointer type ‘RtMidiIn’
lightArray.cpp:24: error: base operand of ‘->’ has non-pointer type ‘RtMidiIn’
lightArray.cpp:34: error: base operand of ‘->’ has non-pointer type ‘RtMidiOut’
lightArray.cpp:38: error: base operand of ‘->’ has non-pointer type ‘RtMidiOut’
lightArray.cpp:50: error: type ‘class RtMidiIn’ argument given to ‘delete’, expected pointer
lightArray.cpp:51: error: type ‘class RtMidiOut’ argument given to ‘delete’, expected pointer
lightArray.cpp: In function ‘int main()’:
lightArray.cpp:79: error: conversion from ‘RtMidiIn*’ to non-scalar type ‘RtMidiIn’ req
任何幫助深表感謝。謝謝!
太棒了。工作完美 - 謝謝。 – distorteddisco 2012-01-11 03:45:35