使用MIDI音序器API的简单节拍器示例
#包括<stdlib.h>
#包括<stdio.h>
#包括<fluidsynth.h>
短 synth_destination,client_destination;
未签名 整型 time_marker;
#定义TEMPO 120
未签名 整型 note_duration = 60000 / TEMPO;
未签名 整型 weak_note = 33;
未签名 整型 strong_note = 34;
未签名 整型 pattern_size = 4;
虚空
虚空
schedule_noteon(整型 , 短 键, 未签名 整型 滴答声)
{
}
虚空
schedule_timer_event()
{
}
虚空
schedule_pattern()
{
整型 我,note_time;
note_time = time_marker;
对于 (i = 0;我<pattern_size; ++ i){
schedule_noteon(9,我??weak_note:strong_note,note_time);
note_time + = note_duration;
}
time_marker = note_time;
}
虚空
{
schedule_timer_event();
schedule_pattern();
}
虚空
用法(烧焦* prog_name)
{
printf("用法:%s soundfont.sf2 [beats [tempo]] \ n",prog_name);
printf("\ t(可选)节拍:模式节拍数,默认为%d \ n",
pattern_size);
printf("\ t(可选)速度:BPM(每分钟节拍数),默认为%d \ n",TEMPO);
}
整型
主要(整型 argc, 烧焦 * argv [])
{
整型 n;
如果 (argc< 2) {
用法(argv [0]);
} 其他 {
合成器);
"fluidsynth_metronome",sequencer_callback,NULL);
如果 (n!= -1){
如果 (argc> 2) {
n = atoi(argv [2]);
如果 (n >0)pattern_size = n;
}
如果 (argc> 3) {
n = atoi(argv [3]);
如果 (n >0)note_duration = 60000 / n;
}
schedule_pattern();
schedule_timer_event();
schedule_pattern();
printf("press <Enter> to stop\n");
n = getchar();
}
}
返回 0;
}