From b8d1bb93d51b80b8b06f2c7e96098a9570861e4f Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 21 Nov 2011 00:03:49 +0100 Subject: Progress... --- maestropond.c | 64 +++++++++++++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/maestropond.c b/maestropond.c index 7385ac8..0c6274c 100644 --- a/maestropond.c +++ b/maestropond.c @@ -48,7 +48,8 @@ enum clef CLEF_TREBLE, CLEF_ALTO, CLEF_TENOR, - CLEF_BASS + CLEF_BASS, + CLEF_NONE }; enum chord_type @@ -93,6 +94,7 @@ struct music unsigned int n_staves; unsigned int n_perc; struct stave staves[8]; + int tempo; /* Maestro music data extracted from file */ unsigned int n_gates; @@ -214,32 +216,39 @@ static void music_attribute(unsigned char ma, struct music *mus) int ct, st; struct chord *n; - st = (ma & 0x60) >> 5; - if ( st > 0 ) st--; /* Horrible fudge, seems to be necessary */ - n = add_chord(mus, st); - n->type = CHORD_CLEF; + /* This seems to mean the clef was deleted */ + if ( !(ma & 0x80) ) { - ct = (ma & 0x18) >> 3; - switch ( ct ) { + st = (ma & 0x60) >> 5; - case 0 : - n->clef = CLEF_TREBLE; - break; + /* Horrible fudge, seems to be necessary */ + if ( st > 0 ) st--; + n = add_chord(mus, st); + n->type = CHORD_CLEF; - case 1 : - n->clef = CLEF_ALTO; - break; + ct = (ma & 0x18) >> 3; + switch ( ct ) { - case 2 : - n->clef = CLEF_TENOR; - break; + case 0 : + n->clef = CLEF_TREBLE; + break; - case 3 : - n->clef = CLEF_BASS; - break; - } + case 1 : + n->clef = CLEF_ALTO; + break; + + case 2 : + n->clef = CLEF_TENOR; + break; - mus->staves[st].last_clef = n->clef; + case 3 : + n->clef = CLEF_BASS; + break; + } + + mus->staves[st].last_clef = n->clef; + + } } else if ( (ma & 0x3) == 0x2 ) { @@ -295,6 +304,10 @@ static struct note pitch_to_note(int pos, int acc, enum clef cl) n.nt = note_letter((pos-1) % 7); break; + case CLEF_NONE : + fprintf(stderr, "No clef yet!\n"); + break; + default: abort(); @@ -511,11 +524,7 @@ static size_t process_stereo_data(unsigned char *f, size_t ptr, size_t len, static size_t process_tempo_data(unsigned char *f, size_t ptr, size_t len, struct music *mus) { - int tempo; - - tempo = f[ptr++]; - printf("Tempo = %i bpm\n", bpm[tempo]); - + mus->tempo = bpm[f[ptr++]]; return ptr; } @@ -626,6 +635,8 @@ static void write_lilypond(struct music *mus, FILE *ofh) { unsigned int i; + fprintf(ofh, "\\tempo 4 = %i\n", mus->tempo); + fprintf(ofh, "\\score {\n"); fprintf(ofh, " <<\n"); @@ -742,6 +753,7 @@ static void convert_file(const char *filename) mus.staves[i].chords = NULL; mus.staves[i].max_chords = 0; mus.staves[i].n_chords = 0; + mus.staves[i].last_clef = CLEF_NONE; } interpret_gates(&mus); -- cgit v1.2.3