Hi,

Have a function that turns text of a guitar chord diagram into the notes it
is composed of.  Would like to get/make a plug-in that puts these notes as a
chord of selected duration into a music score.

Do you have example script of how to put a note of selected duration on a
score?

#include <vector>
#include <valarray>

//---------------------------------------------------------------------------
/*
For standard guitar tuning EADGBE, this function calculates the
guitar notes used in a guitar chord.
Guitar chord diagrams input as text with fret numbers
seperated by commas [no spaces].
In same order as the EADGBE strings.  All six strings must be present in
input
Note: "0" is open string;  "1" is fret 1 etc; "X" or "-" is string not used.

eg   "A" chord can be input as  "-,0,2,2,2,0"
                produces "-0; A3; E4; A4; C#/Db5; E5; "
eg  "Bm" chord can be input as "X,2,4,4,3,2"
                produces "-0; B3; F#/Gb4; B4; D5; F#/Gb5; "

4,9,2,7,11,4 & 3,3,4,4,4,5 numbers below are standard open string guitar
tuning 
these numbers could be easily changed for say DGDGBE guitar tunings etc

*/
void __fastcall TMain_frm::Go_cmdClick(TObject *Sender)
{
    // Set up full octave note text in a vector C to B then can index into
it.
    std::vector<AnsiString> Note_Table(12);
    Note_Table[0] = "C";
    Note_Table[1] = "C#/Db";
    Note_Table[2] = "D";
    Note_Table[3] = "D#/Eb";
    Note_Table[4] = "E";
    Note_Table[5] = "F";
    Note_Table[6] = "F#/Gb";
    Note_Table[7] = "G";
    Note_Table[8] = "G#/Ab";
    Note_Table[9] = "A";
    Note_Table[10] = "A#/Bb";
    Note_Table[11] = "B";

    // Set up index matrix - "index" of open string in the Note_Table
    std::valarray<int> Open_String_Index(6);
    Open_String_Index[0] = 4;
    Open_String_Index[1] = 9;
    Open_String_Index[2] = 2;
    Open_String_Index[3] = 7;
    Open_String_Index[4] = 11;
    Open_String_Index[5] = 4;

    // music staff octave # of the open string guitar notes.  Middle C as
C4.
    std::valarray<int> Open_String_Octave(6);
    Open_String_Octave[0] = 3;
    Open_String_Octave[1] = 3;
    Open_String_Octave[2] = 4;
    Open_String_Octave[3] = 4;
    Open_String_Octave[4] = 4;
    Open_String_Octave[5] = 5;

    // Array frets(6) splits input string into a vector at the commas.
    // Allows for single 0-9 and double 10+ digits.  Can't handle 01, 02!
    std::vector<AnsiString> frets(6);
    AnsiString sixStr = Input_edit->Text; // eg "X,2,4,4,3,2"

    int cp = 1;
    for (int i = 0; i < 5; i++)
    {
        if(sixStr.SubString(cp+1,1)==",")
        {
                frets[i] = sixStr.SubString(cp,1);
                cp += 2;
        }
        else
        {
                frets[i] = sixStr.SubString(cp,2);
                cp += 3;
        }
    }
    frets[5] = sixStr.SubString(cp,sixStr.Length()-cp+1);

    // Functions defined to calculate the music staff notes Notes(6),
    // and octaves Octaves(6) of these six guitar fret positions.
    // Handles "X" or "-" for strings not used.
    // All six strings must be present in input text.
    std::vector<AnsiString> Notes(6);
    for (int i = 0; i < 6; i++)
    {
        if((frets[i]=="X")||(frets[i]=="-"))
        {
                Notes[i] = "-";
        }
        else
        {
                Notes[i] =
Note_Table[div(frets[i].ToInt()+Open_String_Index[i],12).rem];
        }
    }

    std::valarray<int> Octaves(6);
    for (int i = 0; i < 6; i++)
    {
        if((frets[i]=="X")||(frets[i]=="-"))
        {
                Octaves[i] = 0;
        }
        else
        {
                Octaves[i] = Open_String_Octave[i] +
(div(frets[i].ToInt()+Open_String_Index[i],12).quot);
        }
    }

    // Assemble these calculated notes and octaves back into a full string
    // seperated by semi-colons ";" and then display it
    AnsiString out = "";
    for (int i = 0; i < 6; i++)
    {
        out = out + Notes[i] + Octaves[i] + "; ";
    }
    Output_edit->Text = out;  // eg  "X,2,4,4,3,2" becomes "-0; B3; F#/Gb4;
B4; D5; F#/Gb5; " 
}
//---------------------------------------------------------------------------




--
View this message in context: 
http://dev-list.musescore.org/Guitar-Chord-Chart-to-notes-on-a-score-tp7578479.html
Sent from the MuseScore Developer mailing list archive at Nabble.com.

------------------------------------------------------------------------------
DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
_______________________________________________
Mscore-developer mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/mscore-developer

Reply via email to