Exemple #1
0
        public string Apply(string parameters, StaccatoParserContext context)
        {
            StringBuilder buddy = new StringBuilder();

            foreach (string noteString in parameters.Split(' '))
            {
                try
                {
                    Note note = NoteProviderFactory.GetNoteProvider().CreateNote(noteString);
                    int  n    = (int)(note.Duration / ThirtySecondDuration);
                    for (int i = 0; i < n / 2; i++)
                    {
                        buddy.Append(Note.GetToneString(note.Value));
                        buddy.Append("t ");
                        // This function could really be more intelligent. For example,
                        // in the following line, the value of the trill note should actually
                        // be consistent with the scale that is being used, and the note that
                        // is being played. In a C-Major scale with an E note, F would be the
                        // trill note, and that is only +1 from E. Also, the trill could become
                        // increasingly quick.
                        buddy.Append(Note.GetToneString((note.Value + 2)));
                        buddy.Append("t ");
                    }
                }
                catch (Exception)
                {
                    // Nothing to do
                }
            }
            return(buddy.ToString().Trim());
        }
Exemple #2
0
 public static Intervals CreateIntervalsFromNotes(string noteString)
 {
     string[] noteStrings = noteString.Split(' ');
     Note[]   notes       = new Note[noteStrings.Length];
     for (int i = 0; i < noteStrings.Length; i++)
     {
         notes[i] = NoteProviderFactory.GetNoteProvider().CreateNote(noteStrings[i]);
     }
     return(CreateIntervalsFromNotes(notes));
 }
Exemple #3
0
 public Intervals SetRoot(string root)
 {
     Root = NoteProviderFactory.GetNoteProvider().CreateNote(root);
     return(this);
 }
Exemple #4
0
 /// <summary>
 /// Returns true if this interval contains the provided note
 /// in any octave.
 /// Requires that the interval has a root; the octave of the root
 /// or the provided values are ignored.
 /// </summary>
 public bool Has(string note)
 {
     return(Has(NoteProviderFactory.GetNoteProvider().CreateNote(note)));
 }
Exemple #5
0
        /// <summary>
        /// Returns a list of chords represented by this chord progression
        /// </summary>
        /// <returns></returns>
        public Chord[] GetChords()
        {
            if (knownChords != null)
            {
                return(knownChords);
            }

            Chord[] chords       = new Chord[progressionElements.Length];
            Pattern scalePattern = key.Scale.Intervals.SetRoot(key.Root).GetPattern();

            string[] scaleNotes = scalePattern.ToString().Split(' ');
            int      counter    = 0;

            foreach (string progressionElement in progressionElements)
            {
                Note rootNote = NoteProviderFactory.GetNoteProvider()
                                .CreateNote(scaleNotes[RomanNumeralToIndex(progressionElement)]);
                rootNote.UseSameDurationAs(key.Root);
                Intervals intervals = Chord.MAJOR_INTERVALS;
                if ((progressionElement[0] == 'i') || (progressionElement[0] == 'v'))
                {
                    // Checking to see if the progression element is lowercase
                    intervals = Chord.MINOR_INTERVALS;
                }

                if ((progressionElement.ToLower().IndexOf("o") > 0) || (progressionElement.ToLower().IndexOf("d") > 0))
                {
                    // Checking to see if the progression element is diminished
                    intervals = Chord.DIMINISHED_INTERVALS;
                }

                if (progressionElement.EndsWith("7"))
                {
                    if (intervals.Equals(Chord.MAJOR_INTERVALS))
                    {
                        intervals = Chord.MAJOR_SEVENTH_INTERVALS;
                    }
                    else if (intervals.Equals(Chord.MINOR_INTERVALS))
                    {
                        intervals = Chord.MINOR_SEVENTH_INTERVALS;
                    }
                    else if (intervals.Equals(Chord.DIMINISHED_INTERVALS))
                    {
                        intervals = Chord.DIMINISHED_SEVENTH_INTERVALS;
                    }
                }

                if (progressionElement.EndsWith("7%6"))
                {
                    if (intervals.Equals(Chord.MAJOR_INTERVALS))
                    {
                        intervals = Chord.MAJOR_SEVENTH_SIXTH_INTERVALS;
                    }
                    else if (intervals.Equals(Chord.MINOR_INTERVALS))
                    {
                        intervals = Chord.MINOR_SEVENTH_SIXTH_INTERVALS;
                    }
                }

                // Check for inversions
                int inversions = CountInversions(progressionElement);

                chords[counter] = new Chord(rootNote, intervals);
                if (inversions > 0)
                {
                    chords[counter].Inversion = inversions;
                }

                counter++;
            }

            return(chords);
        }
Exemple #6
0
 /// <summary>
 /// Return the frequency in Hertz for the given note.
 /// </summary>
 /// <param name="note">Music string representing the note</param>
 /// <returns>The note frequency in Hz</returns>
 public static double FrequencyForNote(string note)
 {
     return(note.ToUpper().StartsWith("R") ? 0.0d :
            FrequencyForNote(NoteProviderFactory.GetNoteProvider().CreateNote(note).Value));
 }
Exemple #7
0
 public Note(string note)
     : this(NoteProviderFactory.GetNoteProvider().CreateNote(note))
 {
 }