From 4f246b4a5607782e18131cc4d90ec50ea197258d Mon Sep 17 00:00:00 2001 From: Carl Worth Date: Thu, 19 Sep 2013 07:40:58 -0700 Subject: [PATCH] Don't bother looking at signatures that we know can't match Only look at signatures which have a length the same as the number of notes in the current chord being analyzed. --- scherzo.c | 43 +++++++++++++++++++++++++------------------ 1 file changed, 25 insertions(+), 18 deletions(-) diff --git a/scherzo.c b/scherzo.c index d7f78fd..a1a2797 100644 --- a/scherzo.c +++ b/scherzo.c @@ -556,24 +556,31 @@ scherzo_analyze_chord (scherzo_t *scherzo) } } - for (i = 0; i < ARRAY_SIZE (octaves); i++) { - if (_chord_signature_matches (notes, num_notes, octaves[i].pitches, 1)) - chord_name = octaves[i].name; - } - - for (i = 0; i < ARRAY_SIZE (intervals); i++) { - if (_chord_signature_matches (notes, num_notes, intervals[i].pitches, 2)) - chord_name = intervals[i].name; - } - - for (i = 0; i < ARRAY_SIZE (triads); i++) { - if (_chord_signature_matches (notes, num_notes, triads[i].pitches, 3)) - chord_name = triads[i].name; - } - - for (i = 0; i < ARRAY_SIZE(sevenths); i++) { - if (_chord_signature_matches (notes, num_notes, sevenths[i].pitches, 4)) - chord_name = sevenths[i].name; + switch (num_notes) { + case 1: + for (i = 0; i < ARRAY_SIZE (octaves); i++) { + if (_chord_signature_matches (notes, num_notes, octaves[i].pitches, 1)) + chord_name = octaves[i].name; + } + break; + case 2: + for (i = 0; i < ARRAY_SIZE (intervals); i++) { + if (_chord_signature_matches (notes, num_notes, intervals[i].pitches, 2)) + chord_name = intervals[i].name; + } + break; + case 3: + for (i = 0; i < ARRAY_SIZE (triads); i++) { + if (_chord_signature_matches (notes, num_notes, triads[i].pitches, 3)) + chord_name = triads[i].name; + } + break; + case 4: + for (i = 0; i < ARRAY_SIZE(sevenths); i++) { + if (_chord_signature_matches (notes, num_notes, sevenths[i].pitches, 4)) + chord_name = sevenths[i].name; + } + break; } if (chord_name) -- 2.43.0