summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2011-11-25 00:02:06 +0100
committerThomas White <taw@bitwiz.org.uk>2011-11-25 00:02:06 +0100
commit5a5a33e36fc17c32443076d82ba4d877c34500c1 (patch)
treecaf887966edcbe1e08915860d5849ce1ba267843
parentb8d1bb93d51b80b8b06f2c7e96098a9570861e4f (diff)
This gets almost all of "Fanfare"HEADmaster
-rw-r--r--maestropond.c166
1 files 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<n.octave; i++ ) {
+ strcat(t, "'");
+ }
+ } else if ( n.octave < 0 ) {
+ for ( i=0; i<-n.octave; i++ ) {
+ strcat(t, ",");
+ }
+ }
+
+ return t;
+}
+
+
static int is_rest(unsigned char n1)
{
if ( n1 & 0xf8 ) return 0;
@@ -324,11 +366,12 @@ static int is_rest(unsigned char n1)
}
-static int check_note(unsigned char *notes, int *nptr, struct chord *c,
- struct stave *st)
+static int get_note(unsigned char *notes, int *nptr, struct chord *c,
+ struct stave *st)
{
int len, pos, acc;
unsigned char n1, n2;
+ char t[32];
/* Is it a rest? */
n1 = notes[(*nptr)++];
@@ -337,7 +380,6 @@ static int check_note(unsigned char *notes, int *nptr, struct chord *c,
if ( is_rest(n1) ) return 0;
len = (n2 & 0xe0) >> 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; j<mus->n_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<<k)) ) continue;
+ for ( ch=0; ch<8; ch++ ) {
- check_note(mus->notes[k], &nptrs[k], n,
- &mus->staves[j]);
- mus->gates[i] = mus->gates[i] & ~(1<<k);
+ int len;
+ unsigned int stv;
+ struct stave *st = NULL;
+ for ( stv=0; stv<mus->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<<ch)) ) {
+ printf("\n");
+ continue;
+ }
+
+ len = get_note(mus->notes[ch], &nptrs[ch], c, st);
+ mus->gates[i] = mus->gates[i] & ~(1<<ch);
+
+ }
+ printf("--\n");
}
@@ -529,45 +573,6 @@ static size_t process_tempo_data(unsigned char *f, size_t ptr, size_t len,
}
-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;
- int lyo = n.octave - 3;
-
- t[0] = letter(n.nt);
- t[1] = '\0';
-
- if ( lyo > 0 ) {
- for ( i=0; i<lyo; i++ ) {
- strcat(t, "'");
- }
- } else if ( lyo < 0 ) {
- for ( i=0; i<lyo; i++ ) {
- strcat(t, ",");
- }
- }
-
- return t;
-}
-
-
static const char *clef_to_ly(enum clef c)
{
switch ( c ) {
@@ -612,7 +617,7 @@ static void write_stave(FILE *ofh, struct stave *st)
}
if ( c->n_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; j<c->n_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; i<mus->n_staves; i++ ) {
fprintf(ofh, "\\new Staff {\n");
+ fprintf(ofh, "\\tempo 4 = %i\n", mus->tempo);
write_stave(ofh, &mus->staves[i]);
fprintf(ofh, "}\n");