在Processing中提出一些想法之后,我决定将我的MIDI项目转移到C ++以便移植到嵌入式平台。我已经决定将RtMidi库用于MIDI I / O,但是我在编写代码时遇到了一些麻烦。我对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
非常感谢任何帮助。谢谢!
答案 0 :(得分:1)
在main函数中,midiin
和midiout
的类型为RtMidiIn*
和RtMidiOut*
(指向对象的指针),而参数为{{1}类型为printMidiPorts
和RtMidiIn
(对象)。看起来您需要做的就是更改RtMidiOut
的签名。
答案 1 :(得分:0)
您的功能签名错误。
这:void printMidiPorts(RtMidiIn midiin, RtMidiOut midiout)
将midiin和midiout声明为常规值,而不是指针。
void printMidiPorts(RtMidiIn *midiin, RtMidiOut *midiout)
将是您功能的正确签名。