#include "aservelibs/aservelib.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
FILE *textFilePointer;
void notetofile ();
int main()
{
int count, count2, note, vel = 0;
char choice = 'y';
printf("Welcome To Jonny Maguire's Midi record and playback application. Please Select one of the following options...\n\n");
aserveSay("Welcome To Jonny Maguires Midi record and playback application. Please Select one of the following options");
aserveSleep(8000);
while(choice != 'x')
{
for(count = 0; count <=2;)
{
printf("r to Record\np to Playback\nx to exit the program\n");
aserveSay("choose r, to record a sequence, p, to playback your recording. Or select x, at any time to exit the program");
scanf(" %c", &choice);
if(choice =='r')
{
aserveSay("you have chosen to record, play any 16 notes on the midi keyboard");
printf("You have chosen to record, please play 16 notes on the midi keyboard\n\n");
textFilePointer = fopen("recording1.txt", "w");
if(textFilePointer == NULL)
{
printf("Error Opening File!");
}
else
{
for(count2 = 1; count2 <=2; count2++)
{
//Recording 16 note data into txt file
notetofile();
}
}
}
//If P is selected, playback of the txt file
else if (choice == 'p')
{
textFilePointer = fopen("recording1.txt", "r");
if(textFilePointer == NULL)
{
printf("Error Opening File!");
}
//read until end of file and convert frequency
while(!feof(textFilePointer))
{
float frequency;
float amplitude = vel/127.0;
fscanf(textFilePointer, " %d %d\n", ¬e, &vel);
printf(" %d %d\n\n", note, vel);
frequency = 440 * pow(2, (note-69) /12.0);
aserveOscillator(0, frequency, amplitude, 0);
aserveSleep(500);
aserveOscillator(0, 0, 0, 0);
}
}
fclose(textFilePointer);
}
}
return 0;
}
void notestofile (int count, int count2, int note, int vel)
{
//Recording 16 note data into txt file
for (count = 1; count <= 16;)
{
note = aserveGetNote();
vel = aserveGetVelocity();
//only note on messages are sent to file
if(vel > 0)
{
fprintf(textFilePointer, " %d %d\n", note, vel);
printf("%d %d\n", note, vel);
count++;
}
}
}
我尝试放入主函数“ notestofile”的功能给我错误“ Apple Mach-O Linker(id)错误”,并且不会让我构建。该功能应该将注释编号写入文本文件,并且在其主要时起作用,而不是通过该函数传递。提前致谢 :)
最佳答案
您声明并调用notetofile()
,但定义notestofile()
。删除(或添加?)s
修复错误。您还将使用非原型声明,并在不带任何参数的情况下调用它。使用原型可以防止这种情况,因此请进行更改
void notetofile ();
至
void notetofile(int count, int count2, int note, int vel);
关于c - 'notestofile'功能不起作用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29195230/