gnu-music-discuss
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

chord-name.scm: got C++ algorithm, need someone to translate it into sch


From: Amelie Zapf
Subject: chord-name.scm: got C++ algorithm, need someone to translate it into scheme
Date: Tue, 3 Apr 2001 19:30:44 +0200

Hi folks,

can someone please help me out? While doing some clean-up in the chord-name.scm
file (for a clear split between the Banter, Jazz and American chords), I
noticed that all three use the Banter chord compiler to typeset the chords and
all peculiarities of American and Jazz chords are handled by the "exception
list", which makes this list awfully long.

I once wrote an algorithm for compiling *ONE POSSIBLE WAY OF DENOTING* (mind my
words) jazz chords for lily 1.2.17. The same would have to be done here. Now I
tried to translate the whole thing into Scheme - but I do not know enough
Scheme to do that. Could somebody just take that algorithm, translate it to
Scheme and possibly integrate it into chord-name.scm? The variable names are
different, though, so it's a bit hairy.

Hoping to find a volunteer,

best regards,

Amy

Algorithm:

String
Chord::banter_str (Musical_pitch* inversion) const
{
 Musical_pitch tonic = pitch_arr_[0];

 //urg, should do translation in scheme.
 char const *acc[] = {"\\textflat\\textflat ", "\\textflat ", "", "\\textsharp 
" , "\\textsharp\\textsharp "};
 String tonic_str = tonic.str ();
 tonic_str = tonic_str.left_str (1).upper_str () 
         + acc[tonic.accidental_i_ + 2];

 Array<Musical_pitch> add_arr;
 Array<Musical_pitch> sub_arr;
 find_additions_and_subtractions (&add_arr, &sub_arr);

 Array<Musical_pitch> scale;
 for (int i=0; i < 7; i++) scale.push (Musical_pitch (i));

// 7 always means 7-...
//  scale.push (Musical_pitch (6, -1)); // b

 rebuild_transpose (tonic, &scale);
 bool has3m_b = false;
 bool has4_b = false;
 bool hasmaj7_b = false;
 bool hasflat5_b = false;
 bool hassharp5_b = false;
 bool hasalt9_b = false;
 bool hasalt11_b = false;
 bool addition_typeset_b = false;
 bool alt7_typeset_b = false;
 bool add_contained_b = false;
 String no3_str;
 String no5_str;
 String no7_str;
 String no9_str;
 String no11_str;
 String str;
 String sep_str;

 for (int i = 0; i < sub_arr.size (); i++) {
         Musical_pitch p = sub_arr[i];
         int trap = trap_i (tonic, p);
         if (trap == 3) no3_str = "no 3";
         if (trap == 5) no5_str = "no 5";
         if (trap == 7) {
                  no7_str = "add";
                  add_contained_b = true;
         }
         if (trap == 9) {
                 no9_str = "add";
                 no7_str = "";
                 add_contained_b = true;
         }
         if (trap == 11) {
                 no11_str = "add";
                 no9_str = "";
                 add_contained_b = true;
         }
 }


 for (int i = 0; i < add_arr.size (); i++) {
         Musical_pitch p = add_arr[i];
         int trap = trap_i (tonic, p);
         addition_typeset_b = false;
         if (trap == 4) has4_b = true;

/*---Declaration of the accidental---*/
         int accidental = p.accidental_i_ - scale[(trap - 1) % 7].accidental_i_;

/*---Determine if chord is minor---*/
         if ((trap == 3) && (accidental == -1)) {
                 tonic_str += "m";
                 has3m_b = true;
         }
         else if 
         (accidental || (!(trap % 2) || ((i + 1 == add_arr.size()) && (trap > 
5)))) {
                 str += sep_str;
                 if ((trap == 7) && (accidental == 1)) {
                         str += "maj7";

/*---Beginning of addition ---*/
                         hasmaj7_b = true;
                         addition_typeset_b = true;
/*---End of addition---*/
                 }     
                 else {

/*---Beginning of addition---*/
                         if ((trap != 4) && (trap != 5)) {
                                 if ((trap == 9) && (!(hasmaj7_b))) str += 
no7_str;
                                 if (trap == 11) {
                                         if (!(hasmaj7_b)) str += no7_str;
                                         str += no9_str;
                                 }
                                 if (trap == 13) {
                                         if (!(hasmaj7_b)) str += no7_str;
                                         str += no9_str;
                                         str += no11_str;
                                 }
                                 if ((!(add_contained_b)) && (accidental && 
(!(alt7_typeset_b)))) {
                                         str += "7/";
                                         alt7_typeset_b = true;
                                 }
                                 if (accidental) str += accidental < 0 ? 
"\\textflat" : "\\textsharp";
                                 str += to_str (trap);
                                 addition_typeset_b = true;
                         }
                         if ((trap == 5) && (accidental < 0)) hasflat5_b=true;
                         if ((trap == 5) && (accidental > 0)) hassharp5_b=true;
                         if ((trap == 9) && (accidental)) hasalt9_b=true;
                         if ((trap == 11) && (accidental)) hasalt11_b=true;
/*---End of addition---*/
                 }
                 if (addition_typeset_b) {sep_str = "/";} else {sep_str = "";}
         }
 }
 if ((((hasflat5_b) || (hassharp5_b)) || (has4_b)) && (addition_typeset_b)) str 
+= "/";
 if (hasflat5_b && addition_typeset_b) str += "\\textflat";
 if (hassharp5_b && addition_typeset_b) str += "\\textsharp";
 if (hasflat5_b && (!(addition_typeset_b))) str += "-";
 if (hassharp5_b && (!(addition_typeset_b))) str += "+";
 if ((hasflat5_b) || (hassharp5_b)) str += "5";
 if (((hasflat5_b) || (hassharp5_b)) && (has4_b)) str += "/";
 if (has4_b) str += "sus 4";    


 if ((no3_str != "") && (!(has3m_b || has4_b))) {
         str += sep_str;
         str += no3_str;
         sep_str = "/";
 }
 if ((no5_str != "") && (!(hasflat5_b || hassharp5_b))) {
         str += sep_str;
         str += no5_str;
 }





reply via email to

[Prev in Thread] Current Thread [Next in Thread]