Exemplo n.º 1
0
 public void KeyTest(string key, string expectedNote)
 {
     Chords.GermanNotation = false;
     Chords.LongChordNames = false;
     var k = new Key(key);
     Assert.True(k.IsMajor);
     Assert.Equal(expectedNote, k.ToString());
 }
Exemplo n.º 2
0
 /// <summary>
 /// Transposes this chord symbol to another key.
 /// </summary>
 /// <param name="originalKey">The original key to transpose from.</param>
 /// <param name="amount">The amount of semitones to transpose by. Can be positive or negative.</param>
 /// <returns>The transposed chord symbol.</returns>
 public ChordSymbol Transpose(Key originalKey, int amount)
 {
     Key newKey = originalKey.Transpose(amount);
     return ReplaceNotes((note) => note.Transpose(amount).ToString(newKey));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Transpose all chords in a song (can be undone).
 /// </summary>
 /// <param name="song">The song to process.</param>
 /// <param name="originalKey">The original key to transpose from.</param>
 /// <param name="amount">The amount of semitones to transpose by.</param>
 public static void Transpose(Song song, Key originalKey, int amount)
 {
     using (Undo.ChangeFactory.Batch(song, "TransposeChords"))
     {
         foreach (var part in song.Parts)
         {
             foreach (var slide in part.Slides)
             {
                 slide.Text = Transpose(slide.Text, originalKey, amount);
             }
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Returns a <see cref="System.String"/> that represents this instance.
        /// </summary>
        /// <param name="key">The key in which the note should be represented.</param>
        /// <returns>
        /// The name of the note in the given key.
        /// </returns>
        public string ToString(Key key)
        {
            // TODO: use optional argument instead of static flags for format
            if (Chords.LongChordNames && !Chords.GermanNotation)
                throw new InvalidOperationException("Can only use long chord names when german notation is enabled.");

            bool isFlat = key.IsFlat;
            bool longNames = Chords.LongChordNames;

            switch (NormalizeSemitones(SemitonesFromC))
            {
                case 0:
                    return "C";
                case 1:
                    return isFlat ? (longNames ? "Des" : "Db") : (longNames ? "Cis" : "C#");
                case 2:
                    return "D";
                case 3:
                    return isFlat ? (longNames ? "Es" : "Eb") : (longNames ? "Dis" : "D#");
                case 4:
                    return "E";
                case 5:
                    return "F";
                case 6:
                    return isFlat ? (longNames ? "Ges" : "Gb") : (longNames ? "Fis" : "F#");
                case 7:
                    return "G";
                case 8:
                    return isFlat ? (longNames ? "As" : "Ab") : (longNames ? "Gis" : "G#");
                case 9:
                    return "A";
                case 10:
                    return isFlat ? (Chords.GermanNotation ? "B" : "Bb") : (longNames ? "Ais" : "A#");
                case 11:
                    return Chords.GermanNotation ? "H" : "B";
                default:
                    return null; // this can never happen because it's normalized
            }
        }
Exemplo n.º 5
0
 /// <summary>
 /// Transposes all chords in a text.
 /// </summary>
 /// <param name="text">The text to process.</param>
 /// <param name="originalKey">The original key to transpose from.</param>
 /// <param name="amount">The amount of semitones to transpose by.</param>
 /// <returns>The text with all chords transposed.</returns>
 public static string Transpose(string text, Key originalKey, int amount)
 {
     return ReplaceChords(text, (chord) => chord.Transpose(originalKey, amount).Name);
 }