From 5a5a33e36fc17c32443076d82ba4d877c34500c1 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 25 Nov 2011 00:02:06 +0100 Subject: This gets almost all of "Fanfare" --- maestropond.c | 166 ++++++++++++++++++++++++++++++---------------------------- 1 file changed, 85 insertions(+), 81 deletions(-) diff --git a/maestropond.c b/maestropond.c index 0c6274c..9faad1b 100644 --- a/maestropond.c +++ b/maestropond.c @@ -176,7 +176,9 @@ static struct chord *add_chord(struct music *mus, int stave) static int maestro_to_beat(int n) { - return pow(2, n-1); + int v = pow(2, n-1); + if ( v == 0 ) return 1; + return v; } @@ -295,13 +297,15 @@ static struct note pitch_to_note(int pos, int acc, enum clef cl) switch ( cl ) { case CLEF_BASS : - n.octave = (pos+1) / 7; - n.nt = note_letter((pos+1) % 7); + n.octave = (pos-6) / 7 - 1; + n.nt = note_letter((pos-6) % 7); + printf("[%i -> %i:%i]", pos, n.octave, n.nt); break; case CLEF_TREBLE : - n.octave = 2+ ((pos-1) / 7); + n.octave = ((pos+4) / 7) - 1; n.nt = note_letter((pos-1) % 7); + printf("[%i -> %i:%i]", pos, n.octave, n.nt); break; case CLEF_NONE : @@ -317,6 +321,44 @@ static struct note pitch_to_note(int pos, int acc, enum clef cl) } +static char letter(enum note_tone t) +{ + switch ( t ) { + case NOTE_A : return 'a'; + case NOTE_B : return 'b'; + case NOTE_C : return 'c'; + case NOTE_D : return 'd'; + case NOTE_E : return 'e'; + case NOTE_F : return 'f'; + case NOTE_G : return 'g'; + case NOTE_SILENCE : return 's'; + } + + return '?'; +} + + +static const char *note_to_ly(struct note n, char *t) +{ + int i; + + t[0] = letter(n.nt); + t[1] = '\0'; + + if ( n.octave > 0 ) { + for ( i=0; i> 5; - printf("%i ", maestro_to_beat(len)); pos = (n1 & 0xf8) >> 3; acc = n2 & 0x07; @@ -345,7 +387,11 @@ static int check_note(unsigned char *notes, int *nptr, struct chord *c, c->length = maestro_to_beat(len); c->notes[c->n_notes++] = pitch_to_note(pos, acc, st->last_clef); - return 1; + printf("%i %s %p %i\n", maestro_to_beat(len), + note_to_ly(pitch_to_note(pos, acc, st->last_clef), t), + c, c->n_notes-1); + + return len; } @@ -361,43 +407,41 @@ static int channel_in_stave(int ch, int stave, int n_staves) static void process_gate(struct music *mus, int i, int *nptrs) { - unsigned int j; - - if ( mus->gates[i] == 0 ) { - fprintf(stderr, "Empty gate encountered!\n"); - return; - } - - printf("("); - do { - - for ( j=0; jn_staves; j++ ) { - - struct chord *n; - int k; - - n = add_chord(mus, j); - n->type = CHORD_MUSIC; - printf("st%i: ", j); - - /* Find the notes of this length on this stave */ - for ( k=0; k<8; k+=4 ) { /* FIXME! */ + int ch; + struct stave *os = NULL; + struct chord *c; - if ( !channel_in_stave(k, j, mus->n_staves) ) { - continue; - } - if ( !(mus->gates[i] & (1<notes[k], &nptrs[k], n, - &mus->staves[j]); - mus->gates[i] = mus->gates[i] & ~(1<n_staves; stv++ ) { + if ( channel_in_stave(ch, stv, mus->n_staves) ) { + st = &mus->staves[stv]; + break; } + } + assert(st != NULL); + if ( st != os ) { + c = add_chord(mus, stv); + c->type = CHORD_MUSIC; + os = st; } - } while ( 0 && (mus->gates[i] != 0) ); /* FIXME! */ - printf(")"); + printf("%i : ", ch); + if ( !(mus->gates[i] & (1<notes[ch], &nptrs[ch], c, st); + mus->gates[i] = mus->gates[i] & ~(1< 0 ) { - for ( i=0; in_notes == 0 ) { - fprintf(stderr, "I don't understand this chord.\n"); + //fprintf(stderr, "I don't understand this chord.\n"); continue; } @@ -624,7 +629,7 @@ static void write_stave(FILE *ofh, struct stave *st) fprintf(ofh, "<"); for ( j=0; jn_notes; j++ ) { - fprintf(ofh, "%s ", note_to_ly(c->notes[0], t)); + fprintf(ofh, "%s ", note_to_ly(c->notes[j], t)); } fprintf(ofh, ">%i ", c->length); @@ -635,14 +640,13 @@ 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"); for ( i=0; in_staves; i++ ) { fprintf(ofh, "\\new Staff {\n"); + fprintf(ofh, "\\tempo 4 = %i\n", mus->tempo); write_stave(ofh, &mus->staves[i]); fprintf(ofh, "}\n"); -- cgit v1.2.3