Added a simple music sheet generator and updating repo
This commit is contained in:
parent
cf83fe61ae
commit
f8592113e8
56
generateur_partition.py
Executable file
56
generateur_partition.py
Executable file
@ -0,0 +1,56 @@
|
||||
#!/usr/bin/python
|
||||
|
||||
import sys
|
||||
import getopt
|
||||
|
||||
try:
|
||||
opts, args = getopt.gnu_getopt(sys.argv, "ho:", ["help", "output"])
|
||||
except getopt.GetoptError:
|
||||
sys.exit("[ERROR] Unable to parse command line arguments. "
|
||||
"See -h option for more infos on how to use.")
|
||||
|
||||
for opt, arg in opts:
|
||||
if opt in ("-h", "--help"):
|
||||
print("Music sheet generator for the sound player. Usage :")
|
||||
print("-h \t --help \t Displays this help message")
|
||||
print("-o file \t --output file \t Save the generated music sheet to "
|
||||
"the specified file")
|
||||
|
||||
elif opt in ("-o", "--output"):
|
||||
output = arg
|
||||
|
||||
|
||||
continue_while = True
|
||||
notes = {"RE": 294, "MI": 330, "FA": 349, "SOL": 392, "LA": 440, "SI": 494,
|
||||
"DO": 523, "RE2": 587, "MI2": 659, "FA2": 699, "SOL2": 794, "LA2": 880,
|
||||
"SI2": 988}
|
||||
partition = ''
|
||||
|
||||
while continue_while:
|
||||
note = input("Note ? ")
|
||||
|
||||
if note.lower() == "quit":
|
||||
continue_while = False
|
||||
continue
|
||||
|
||||
length = input("Length ? ")
|
||||
|
||||
try:
|
||||
length = int(length)
|
||||
except ValueError:
|
||||
continue_while = False
|
||||
sys.exit("[ERROR] Entered length is not a number.")
|
||||
|
||||
if note.upper() not in notes.keys():
|
||||
sys.exit("[ERROR] Unknown note "+note+".")
|
||||
else:
|
||||
partition += str(notes[note.upper()])+":"+str(length)+"\n"
|
||||
print("\nPartition :\n"+partition)
|
||||
|
||||
if output != '':
|
||||
try:
|
||||
with open(output, 'w') as output_fh:
|
||||
output_fh.write(partition)
|
||||
except:
|
||||
sys.exit("[ERROR] Unable to write music sheet to the specified output"
|
||||
"file.")
|
@ -1,79 +0,0 @@
|
||||
# include "stdio.h"
|
||||
# include "stdlib.h"
|
||||
# include "string.h"
|
||||
|
||||
int main()
|
||||
{
|
||||
char note[100];
|
||||
int stop = 0, duree = 0;
|
||||
|
||||
while(stop == 0)
|
||||
{
|
||||
printf("Note ? ");
|
||||
scanf("%s", note);
|
||||
|
||||
printf("Durée ? ");
|
||||
scanf("%d", duree);
|
||||
|
||||
switch(note)
|
||||
{
|
||||
case "RE":
|
||||
printf("294:%d\n",duree);
|
||||
break;
|
||||
|
||||
case "MI":
|
||||
printf("330:%d\n",duree);
|
||||
break;
|
||||
|
||||
case "FA":
|
||||
printf("349:%d\n",duree);
|
||||
break;
|
||||
|
||||
case "SOL":
|
||||
printf("392:%d\n",duree);
|
||||
break;
|
||||
|
||||
case "LA":
|
||||
printf("440:%d\n",duree);
|
||||
break;
|
||||
|
||||
case "SI":
|
||||
printf("494:%d\n",duree);
|
||||
break;
|
||||
|
||||
case "DO":
|
||||
printf("523:%d\n",duree);
|
||||
break;
|
||||
|
||||
case "RE2":
|
||||
printf("587:%d\n",duree);
|
||||
break;
|
||||
|
||||
case "MI2":
|
||||
printf("659:%d\n",duree);
|
||||
break;
|
||||
|
||||
case "FA2":
|
||||
printf("699:%d\n",duree);
|
||||
break;
|
||||
|
||||
case "SOL2":
|
||||
printf("794:%d\n",duree);
|
||||
break;
|
||||
|
||||
case "LA2":
|
||||
printf("880:%d\n",duree);
|
||||
break;
|
||||
|
||||
case "SI2":
|
||||
printf("988:%d\n",duree);
|
||||
break;
|
||||
|
||||
default:
|
||||
stop = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
|
||||
# include "stdio.h"
|
||||
# include "stdlib.h"
|
||||
# include "string.h"
|
||||
# include "wave_stuff.h"
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
float *xd;
|
||||
int i, freq = 0, nx = 0, canal = 0, verbose = 0;
|
||||
|
||||
if (argc < 3)
|
||||
{
|
||||
fprintf(stderr,"Usage: %s wavefile canal [verbose]\nExample %s d:\\low.wav 1\n",argv[0],argv[0]);
|
||||
return 0;
|
||||
}
|
||||
if (sscanf(argv[2],"%d",&canal) != 1)
|
||||
{
|
||||
fprintf(stderr,"cannot read canal value %s\n",argv[2]);
|
||||
return 1;
|
||||
}
|
||||
if (argc > 3) sscanf(argv[3],"%d",&verbose);
|
||||
xd = read_wave_create_array(argv[1], canal, verbose, &nx, &freq);
|
||||
if (xd == NULL)
|
||||
{
|
||||
fprintf(stderr,"cannot read canal wave file %s\n",argv[1]);
|
||||
return 2;
|
||||
}
|
||||
printf("%% %s wave file, canal %d, frequence %d, nb. of sample %d\n",argv[1],canal,freq,nx);
|
||||
for (i = 0; i < nx; i++)
|
||||
printf("%d\n",(int)xd[i]);
|
||||
|
||||
return 0;
|
||||
}
|
@ -1,77 +0,0 @@
|
||||
|
||||
# include "stdio.h"
|
||||
# include "stdlib.h"
|
||||
# include "string.h"
|
||||
# include "wave_stuff.h"
|
||||
|
||||
# define MAX_LINE_LENGTH 1024
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char line[MAX_LINE_LENGTH], *l;
|
||||
float *xd = NULL;
|
||||
int i, freq = 0, nx = 0, canal = 0, BitsPerSample = 16, data, min, max;
|
||||
FILE *fp;
|
||||
|
||||
if (argc < 4)
|
||||
{
|
||||
fprintf(stderr,"Usage: %s wave_data.txt wavefile_to_create.wav frequency BitsPerSample\nExample %s d:\\low.wav 44100 16\n",argv[0],argv[0]);
|
||||
return 0;
|
||||
}
|
||||
if ((fp = fopen(argv[1], "r")) == NULL)
|
||||
{
|
||||
fprintf(stderr,"cannot open file %s\n",argv[1]);
|
||||
return 1;
|
||||
}
|
||||
if (sscanf(argv[3],"%d",&freq) != 1)
|
||||
{
|
||||
fprintf(stderr,"cannot read freq value %s\n",argv[3]);
|
||||
return 1;
|
||||
}
|
||||
if (argc > 4) sscanf(argv[4],"%d",&BitsPerSample);
|
||||
|
||||
for(nx = 0, l = fgets(line, MAX_LINE_LENGTH, fp); l != NULL; l = fgets(line, MAX_LINE_LENGTH, fp))
|
||||
{
|
||||
if (strcspn(line,"%") >= strlen(line))
|
||||
{
|
||||
if (sscanf(line,"%d",&data) == 1)
|
||||
nx++;
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
if (nx <= 0)
|
||||
{
|
||||
fprintf(stderr,"could not read data");
|
||||
return 2;
|
||||
}
|
||||
xd = (float*)calloc(nx,sizeof(float));
|
||||
if (xd == NULL)
|
||||
{
|
||||
fprintf(stderr,"could not create float array");
|
||||
return 2;
|
||||
}
|
||||
min = max = 0;
|
||||
fp = fopen(argv[1], "r");
|
||||
for(i = 0, l = fgets(line, MAX_LINE_LENGTH, fp); l != NULL; l = fgets(line, MAX_LINE_LENGTH, fp))
|
||||
{
|
||||
if (strcspn(line,"%") >= strlen(line))
|
||||
{
|
||||
if (sscanf(line,"%d",&data) == 1)
|
||||
{
|
||||
xd[i] = (float)data;
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
fclose(fp);
|
||||
printf("%d sample read\n",nx);
|
||||
i = save_wave_from_array(xd, nx, argv[2], freq, BitsPerSample);
|
||||
if (i)
|
||||
{
|
||||
fprintf(stderr,"cannot save wave file %s\n",argv[2]);
|
||||
return 2;
|
||||
}
|
||||
free(xd);
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user