Example #1
0
        /// <summary>
        /// Get chord diagram settings based on guitar model tuning/strings etc
        /// </summary>
        /// <param name="rootNote"></param>
        /// <param name="chordType"></param>
        /// <returns></returns>
        public ChordDiagram GetChordDiagramOld(Note rootNote, string chordType)
        {
            ChordManager chordManager = new ChordManager();
            ChordDiagram chordDiagram = new ChordDiagram();

            chordDiagram.RootNote = rootNote;
            chordDiagram.CurrentChordDefinition = chordManager.GetChordDefinition(chordType);

            //determine fretted notes per string based on current guitar model settings
            List <Note> notes = chordManager.GetChordNotes(rootNote, chordType, StartingFretPos);

            ///http://en.wikipedia.org/wiki/Chord_(music)
            bool hasChordSequenceStarted = false; //set to true once the target starting note is found, depending on the inversion (if any root, 1st pos , 2nd pos etc)

            for (int i = 0; i < NumberOfStrings; i++)
            {
                System.Diagnostics.Debug.WriteLine("Checking String:" + i);
                bool currentNoteFound = false;
                for (int n = 0; n < notes.Count; n++)
                {
                    Note chordNote = notes[n];

                    System.Diagnostics.Debug.WriteLine("Checking Note:" + chordNote.ToString());

                    if (!currentNoteFound)
                    {
                        List <int> currentNoteFrets = GuitarStrings[i].GetNoteFretPositions(chordNote, StartingFretPos);

                        if (currentNoteFrets.Count > 0)
                        {
                            if (currentNoteFrets[0] < MaximumChordPositionStretch)
                            {
                                if (!currentNoteFound)
                                {
                                    if (n == 0)
                                    {
                                        hasChordSequenceStarted = true;
                                    }

                                    //only add fretted note if root note has been found
                                    if (hasChordSequenceStarted)
                                    {
                                        chordDiagram.FrettedStrings[i] = new Music.FrettedNote()
                                        {
                                            Fret = currentNoteFrets[0]
                                        };
                                    }
                                    currentNoteFound = true;
                                }
                            }
                        }
                    }
                }
            }

            return(chordDiagram);
        }
Example #2
0
    private void AddNewChord(int targetIndex = -1)
    {
        GameObject newDiagram = Instantiate <GameObject>(ChordDiagramTemplate, ScrollContainer);

        newDiagram.transform.SetSiblingIndex(targetIndex >= 0 ? targetIndex : ScrollContainer.childCount - 3);
        ChordDiagram diagram = newDiagram.GetComponent <ChordDiagram>();

        diagram.Initialize(OnChordRemoved, OnChordDuplicated, AddNewElement, MoveElement);
        chords.Add(diagram);
    }
Example #3
0
        /// <summary>
        /// returns the fretted notes of a chord based on root note and chord type
        /// </summary>
        /// <param name="rootNote"></param>
        /// <param name="chordType"></param>
        /// <returns></returns>
        public ChordDiagram GetChordDiagram(Note rootNote, string chordType)
        {
            ChordManager chordManager = new ChordManager();
            ChordDiagram chordDiagram = new ChordDiagram();

            chordDiagram.RootNote = rootNote;
            chordDiagram.CurrentChordDefinition = chordManager.GetChordDefinition(chordType);

            //determine notes in the given chord  : http://en.wikipedia.org/wiki/Chord_(music)
            List <Note> notes      = chordManager.GetChordNotes(rootNote, chordType, StartingFretPos);
            List <Note> notesFound = new List <Note>();

            //determine which string/frets would be fretted based on current guitar model settings
            bool hasChordSequenceStarted = false; //set to true once the target starting note is found, depending on the inversion (if any root, 1st pos , 2nd pos etc)

            //basic algorithm is to fret the root note of the chord on the first string possible (low to high)
            //then we fret the note on each string with the lowest fret position regardless of which interval it is in chord

            for (int currentStringIndex = 0; currentStringIndex < NumberOfStrings; currentStringIndex++)
            {
                //System.Diagnostics.Debug.WriteLine("Checking String:" + i);
                var chordNotesOnString = new List <Music.FrettedNote>();

                //get collection of notes applicable to this chord on current string
                for (int chordNoteIndex = 0; chordNoteIndex < notes.Count; chordNoteIndex++)
                {
                    var frettedNote = FindChordNote(chordDiagram, notes[chordNoteIndex], ref hasChordSequenceStarted, currentStringIndex, chordNoteIndex);
                    if (frettedNote != null)
                    {
                        chordNotesOnString.Add(frettedNote);
                    }
                }

                //got a collection of notes for the chord on current string, decide which one to fret in chord diagram
                if (chordNotesOnString.Any())
                {
                    //if chord not yet started, use position of root/bass note on string (if any within range of fretted start position), otherwise choose note with minimum fret position
                    if (!chordDiagram.FrettedStrings.Any(c => c != null))
                    {
                        if (chordNotesOnString.Any(c => c.Note == notes[0]))
                        {
                            chordDiagram.FrettedStrings[currentStringIndex] = chordNotesOnString.Where(c => c.Note == notes[0]).First();
                        }
                    }
                    else
                    {
                        chordDiagram.FrettedStrings[currentStringIndex] = chordNotesOnString.OrderBy(f => f.Fret).First();
                    }
                }
            }

            return(chordDiagram);
        }
        protected ChordDiagram ReadChordDiagram()
        {
            ChordDiagram chord  = new ChordDiagram();
            byte         header = ReadByte();

            if ((header & 0x01) == 0)
            {
                chord.Name = ReadStringInteger();
                //chord.setName(readStringByteSizeOfInteger());
                chord.BaseFret = ReadInt();
                //chord.setFirstFret(readInt());
                if (chord.BaseFret != 0)
                {
                    for (int i = 0; i < 6; i++)
                    {
                        int fret = ReadInt();
                        if (i < 6)
                        {
                            chord.Frets[i] = fret;
                        }
                    }
                }
            }
            else
            {
                stream.Seek(17, SeekOrigin.Current);
                chord.Name = ReadString(21);
                stream.Seek(4, SeekOrigin.Current);
                chord.BaseFret = ReadInt();
                for (int i = 0; i < 7; i++)
                {
                    int fret = ReadInt();
                    if (i < 6)
                    {
                        chord.Frets[i] = fret;
                    }
                }
                stream.Seek(32, SeekOrigin.Current);
            }

            return(chord);
        }
        protected ChordDiagram ReadChordDiagram()
        {
            ChordDiagram chord = new ChordDiagram();

            Skip(17);
            chord.Name = ReadString(22);
            Skip(4);
            chord.BaseFret = ReadInt();

            for (int i = 0; i < 7; i++)
            {
                int fret = ReadInt();
                if (i < 6)
                {
                    chord.Frets[i] = fret;
                }
            }
            Skip(32);
            return(chord);
        }
        protected ChordDiagram ReadChordDiagram()
        {
            ChordDiagram chord  = new ChordDiagram();
            byte         header = ReadByte();

            if ((header & 0x01) == 0)
            {
                chord.Name = ReadStringInteger();
                //chord.setName(readStringByteSizeOfInteger());
                chord.BaseFret = ReadInt();
                //chord.setFirstFret(readInt());
                if (chord.BaseFret != 0)
                {
                    for (int i = 0; i < 6; i++)
                    {
                        int fret = ReadInt();
                        if (i < 6)
                        {
                            chord.Frets[i] = fret;
                        }
                    }
                }
            }
            else
            {
                Skip(25);
                chord.Name     = ReadString(35);
                chord.BaseFret = ReadInt();
                for (int i = 0; i < 6; i++)
                {
                    int fret = ReadInt();
                    if (i < 6)
                    {
                        chord.Frets[i] = fret;
                    }
                }
                Skip(36);
            }

            return(chord);
        }
Example #7
0
        private Music.FrettedNote FindChordNote(ChordDiagram chordDiagram, Note chordNote, ref bool hasChordSequenceStarted, int currentStringIndex, int currentNoteIndex)
        {
            bool currentNoteFound = false;

            if (!currentNoteFound)
            {
                List <int> currentNoteFrets = GuitarStrings[currentStringIndex].GetNoteFretPositions(chordNote, StartingFretPos);

                if (currentNoteFrets.Count > 0)
                {
                    if (currentNoteFrets[0] < StartingFretPos + MaximumChordPositionStretch)
                    {
                        if (!currentNoteFound)
                        {
                            //if note is root of chord then chord sequence has started and can start fretting notes
                            if (currentNoteIndex == 0)
                            {
                                hasChordSequenceStarted = true;
                            }

                            //only add fretted note if root note has been found
                            if (hasChordSequenceStarted)
                            {
                                currentNoteFound = true;
                                return(new Music.FrettedNote()
                                {
                                    Fret = currentNoteFrets[0], Note = chordNote
                                });
                            }
                        }
                    }
                }
            }

            return(null);
        }
Example #8
0
 private void OnChordDuplicated(ChordDiagram diagram)
 {
     AddNewChord(diagram.CurrentChord);
 }
Example #9
0
 private void OnChordRemoved(ChordDiagram diagram)
 {
     chords.Remove(diagram);
 }
        protected ChordDiagram ReadChordDiagram()
        {
            ChordDiagram chord = new ChordDiagram();
            byte header = ReadByte();
            if ((header & 0x01) == 0)
            {
                chord.Name = ReadStringInteger();
                //chord.setName(readStringByteSizeOfInteger());
                chord.BaseFret = ReadInt();
                //chord.setFirstFret(readInt());
                if (chord.BaseFret != 0)
                {
                    for (int i = 0; i < 6; i++)
                    {
                        int fret = ReadInt();
                        if (i < 6)
                        {
                            chord.Frets[i] = fret;
                        }
                    }
                }
            }
            else
            {
                stream.Seek(17, SeekOrigin.Current);
                chord.Name = ReadString(21);
                stream.Seek(4, SeekOrigin.Current);
                chord.BaseFret = ReadInt();
                for (int i = 0; i < 7; i++)
                {
                    int fret = ReadInt();
                    if (i < 6)
                    {
                        chord.Frets[i] = fret;
                    }
                }
                stream.Seek(32, SeekOrigin.Current);
            }

            return chord;
        }
        protected ChordDiagram ReadChordDiagram()
        {
            ChordDiagram chord = new ChordDiagram();
            byte header = ReadByte();
            if ((header & 0x01) == 0)
            {
                chord.Name = ReadStringInteger();
                //chord.setName(readStringByteSizeOfInteger());
                chord.BaseFret = ReadInt();
                //chord.setFirstFret(readInt());
                if (chord.BaseFret != 0)
                {
                    for (int i = 0; i < 6; i++)
                    {
                        int fret = ReadInt();
                        if (i < 6)
                        {
                            chord.Frets[i] = fret;
                        }
                    }
                }
            }
            else
            {
                Skip(25);
                chord.Name = ReadString(35);
                chord.BaseFret = ReadInt();
                for (int i = 0; i < 6; i++)
                {
                    int fret = ReadInt();
                    if (i < 6)
                    {
                        chord.Frets[i] = fret;
                    }
                }
                Skip(36);
            }

            return chord;
        }
        protected ChordDiagram ReadChordDiagram()
        {
            ChordDiagram chord = new ChordDiagram();
            Skip(17);
            chord.Name = ReadString(22);
            Skip(4);
            chord.BaseFret = ReadInt();

            for (int i = 0; i < 7; i++)
            {
                int fret = ReadInt();
                if (i < 6)
                {
                    chord.Frets[i] = fret;
                }
            }
            Skip(32);
            return chord;
        }