我正在尝试使用以下代码制作旋律。问题是试图让序列播放节奏数组中的节奏值。我基本上想弹奏音符,然后在指定时间内关闭速度并播放序列中的下一个音符。
任何帮助将不胜感激。
int playMidi()
{
//pitch array with constants defined for pitch numbers: ex. C4 = 60
int pitchArray[11] {C4, A5, E4, F3, D4, FS5, BF4, CS3, FS5, C3, DF4}; /
//velocity array with constants defined for velocity: ex. QN = 1, EN = 0.5
int velocityArray[11] {FORTE, PIANISSIMO, MEZZO_FORTE, PIANISSIMO, FORTISSIMO,
MEZZO_PIANO, PIANISSIMO, FORTE, MEZZO_PIANO,FORTE, FORTISSIMO};
//rhythm array with constants defined for rhythm values: ex. = 110
double rhythmArray[11] {EN, SN, SN, EN, QN, EN, EN, EN, TSN,TSN, SN};
for(int i=0; i<11; i++)
{
UInt32 noteOnCommand = kMidiMessage_NoteOn << 4 | midiChannelInUse;
std::cout<< "The current pitch is: "
<<pitchArray[i] << "The velocity is: " <<velocityArray[i]
<< " and the rhythmic value is: "<<rhythmArray[i]<< "\n";
MusicDeviceMIDIEvent(synthUnit,
noteOnCommand,
pitchArray[i],
velocityArray[i],
0);
// sleep for a second
sleep(1);
}
return 0;
}