2012-01-11 3 views
0

Processing에서 몇 가지 아이디어를 제시 한 후, 임베디드 플랫폼으로의 이식성을 위해 C++로 MIDI 프로젝트를 이동하기로 결정했습니다. 나는 MIDI I/O를 위해 RtMidi 라이브러리를 사용하기로 결정했으나 원하는대로 코드를 배치하는 데 어려움을 겪고있다. 나는 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 

. 감사!

답변

1

그것은 메인 함수 모양, 및 midiinmidiout는 유형 및 RtMidiIn*RtMidiOut* (객체에 대한 포인터)의이다. printMidiPorts의 서명을 변경하면됩니다.

+0

환상적입니다. 완벽하게 일했습니다 - 고마워요. – distorteddisco

0

함수 서명이 잘못되었습니다.

this : void printMidiPorts(RtMidiIn midiin, RtMidiOut midiout) 은 midiin 및 midiout을 포인터가 아닌 일반 값으로 선언합니다.

void printMidiPorts(RtMidiIn *midiin, RtMidiOut *midiout)은 귀하의 기능에 대한 올바른 서명입니다. printMidiPorts의 파라미터 유형과 RtMidiInRtMidiOut (개체) 동안

관련 문제