summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2011-11-20 23:35:03 +0100
committerThomas White <taw@bitwiz.org.uk>2011-11-20 23:35:03 +0100
commit424ed17b1398ae447d28720183e97c511a031d19 (patch)
treeba2da3e6d838e15df588f17b4f61863b77ec3796
parentef2baf8076db297fbb979fde6c3e911a391bd15a (diff)
Aha, rhythm is reading correctly!
-rw-r--r--maestropond.c65
1 files changed, 20 insertions, 45 deletions
diff --git a/maestropond.c b/maestropond.c
index 6cf1ca0..7385ac8 100644
--- a/maestropond.c
+++ b/maestropond.c
@@ -311,50 +311,25 @@ static int is_rest(unsigned char n1)
}
-static int find_max_length(unsigned char g, unsigned char **notes, int *nptrs)
-{
- int ch;
- int lmax = 100;
-
- for ( ch=0; ch<8; ch++ ) {
-
- int len;
-
- if ( !(g & 1<<ch) ) continue;
-
- len = (notes[ch][nptrs[ch]] & 0xe0) >> 5;
- if ( len < lmax ) lmax = len;
-
- }
-
- if ( lmax == 100 ) {
- fprintf(stderr, "No note length in gate!\n");
- }
-
- return lmax;
-}
-
-
-static int check_note(unsigned char *notes, int *nptr, struct chord *c, int ls,
+static int check_note(unsigned char *notes, int *nptr, struct chord *c,
struct stave *st)
{
int len, pos, acc;
unsigned char n1, n2;
- /* Is it the right length? If not, save it for the next chord */
- len = (notes[*nptr] & 0xe0) >> 5;
- if ( len != ls ) return 0;
-
/* Is it a rest? */
- n1 = notes[*nptr];
+ n1 = notes[(*nptr)++];
+ n2 = notes[(*nptr)++];
+
if ( is_rest(n1) ) return 0;
- (*nptr)++;
- n2 = notes[*nptr++];
+ len = (n2 & 0xe0) >> 5;
+ printf("%i ", maestro_to_beat(len));
pos = (n1 & 0xf8) >> 3;
acc = n2 & 0x07;
+ c->length = maestro_to_beat(len);
c->notes[c->n_notes++] = pitch_to_note(pos, acc, st->last_clef);
return 1;
@@ -373,13 +348,15 @@ 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 l, j;
+ unsigned int j;
- printf("(");
- while ( mus->gates[i] != 0 ) {
+ if ( mus->gates[i] == 0 ) {
+ fprintf(stderr, "Empty gate encountered!\n");
+ return;
+ }
- l = find_max_length(mus->gates[i], mus->notes, nptrs);
- printf("%i ", l);
+ printf("(");
+ do {
for ( j=0; j<mus->n_staves; j++ ) {
@@ -387,28 +364,26 @@ static void process_gate(struct music *mus, int i, int *nptrs)
int k;
n = add_chord(mus, j);
- n->length = maestro_to_beat(l);
n->type = CHORD_MUSIC;
+ printf("st%i: ", j);
/* Find the notes of this length on this stave */
- for ( k=0; k<8; k++ ) {
+ for ( k=0; k<8; k+=4 ) { /* FIXME! */
if ( !channel_in_stave(k, j, mus->n_staves) ) {
continue;
}
if ( !(mus->gates[i] & (1<<k)) ) continue;
- if ( check_note(mus->notes[k], &nptrs[k], n, l,
- &mus->staves[j]) )
- {
- mus->gates[i] = mus->gates[i] ^ (1<<k);
- }
+ check_note(mus->notes[k], &nptrs[k], n,
+ &mus->staves[j]);
+ mus->gates[i] = mus->gates[i] & ~(1<<k);
}
}
- }
+ } while ( 0 && (mus->gates[i] != 0) ); /* FIXME! */
printf(")");
}