/// <summary> /// Builds a scale. /// </summary> /// <param name="tonic">The tonic.</param> /// <param name="pattern">The scale pattern.</param> /// <param name="positionInOctaveToSequenceIndex">Must have 12 elements, and is filled with /// the 0-indexed scale position (or -1) for each position in the octave.</param> /// <param name="noteSequence">Must have pattern.Ascent.Length elements, and is filled with /// the notes for each scale degree.</param> /// <param name="numAccidentals">Filled with the total number of accidentals in the built /// scale.</param> private static void Build(Note tonic, ScalePattern pattern, int[] positionInOctaveToSequenceIndex, Note[] noteSequence, out int numAccidentals) { numAccidentals = 0; for (int i = 0; i < 12; ++i) { positionInOctaveToSequenceIndex[i] = -1; } Pitch tonicPitch = tonic.PitchInOctave(0); for (int i = 0; i < pattern.Ascent.Length; ++i) { Pitch pitch = tonicPitch + pattern.Ascent[i]; Note note; if (pattern.Ascent.Length == 7) { char letter = (char)(i + (int)(tonic.Letter)); if (letter > 'G') { letter = (char)((int)letter - 7); } note = pitch.NoteWithLetter(letter); } else { note = pitch.NotePreferringSharps(); } noteSequence[i] = note; positionInOctaveToSequenceIndex[pitch.PositionInOctave()] = i; } }
private static void Build(Note root, ChordPattern pattern, bool[] positionInOctaveToContains, Note[] noteSequence) { for (int i = 0; i < 12; ++i) { positionInOctaveToContains[i] = false; } Pitch rootPitch = root.PitchInOctave(0); for (int i = 0; i < pattern.Ascent.Length; ++i) { Pitch pitch = rootPitch + pattern.Ascent[i]; char letter = (char)(pattern.LetterOffsets[i] + (int)(root.Letter)); while (letter > 'G') { letter = (char)((int)letter - 7); } noteSequence[i] = pitch.NoteWithLetter(letter); positionInOctaveToContains[pitch.PositionInOctave()] = true; } }
string transpose(string musicKey, string targetKey, int direction, bool flat,out Midi.Pitch outpitch) { //convert the key to a number: //"G8" = 8 * "8" + 7 bool black = musicKey.Contains("Sharp"); musicKey = musicKey.Replace("Sharp", ""); string scale = "CDEFGABC"; int y = int.Parse(""+musicKey[1]); int x = scale.IndexOf(musicKey[0]); if (flat && black) //add1 to x x = (x + 1); if (x == 7) { x %= 7; y++; } int keyID = y * 7 + x; switch(targetKey) { case "G": direction = 3; break; case "A": direction = 2; break; case "B": direction =1; break; } keyID += direction; ; y = keyID / 7; x = keyID % 7; string preout = "" + scale[x] + ((black)?("Sharp"):("")) +y.ToString(); string cnote = "" + preout[0]; // bool sharp = musicKey.Contains("Sharp"); if (black) cnote += "#"; Midi.Note outnote = new Midi.Note(cnote); outpitch = outnote.PitchInOctave(y); return preout; }
private void btnCreate_Click(object sender, RoutedEventArgs e) { // scale mode? if (!(bool)chkScaleMode.IsChecked) currentScaleNoteIndex = 0; // otherwise, create a cube that matches the specifications we just set Cube cube = new NullCube(Engine.Engine.Origin, 0); // yank values from comboboxes n shit Note note = new Note((string)((ComboBoxItem)cmbNote.SelectedItem).Content); int octave = int.Parse((string)((ComboBoxItem)cmbOctave.SelectedItem).Content); ChordPattern chordPattern = Chord.Major; ScalePattern scalePattern = Scale.Major; switch ((string)((ComboBoxItem)cmbScale.SelectedItem).Content) { case "Major": scalePattern = Scale.Major; break; case "HarmonicMinor": scalePattern = Scale.HarmonicMinor; break; case "MelodicMinorAscending": scalePattern = Scale.MelodicMinorAscending; break; case "MelodicMinorDescending": scalePattern = Scale.MelodicMinorDescending; break; case "NaturalMinor": scalePattern = Scale.NaturalMinor; break; } switch ((string)((ComboBoxItem)cmbChordType.SelectedItem).Content) { case "Major": chordPattern = Chord.Major; break; case "Minor": chordPattern = Chord.Minor; break; case "Seventh": chordPattern = Chord.Seventh; break; case "Augmented": chordPattern = Chord.Augmented; break; case "Diminished": chordPattern = Chord.Diminished; break; } Scale scale = new Scale(note, scalePattern); // scalemode translation note = scale.NoteSequence[currentScaleNoteIndex++ % 7]; Pitch pitch = note.PitchInOctave(octave); int chordInversion = int.Parse((string)((ComboBoxItem)cmbInversion.SelectedItem).Content); Chord chord = new Chord(note, chordPattern, chordInversion); // single note cube if ((bool)Note.IsChecked) { cube = new SingleNoteCube(Engine.Engine.Origin, _Constants.CreateHandDistance / 2.0, pitch, CurrentInstrument, App.OutputDevice, CurrentChannel); } if ((bool)Chord2.IsChecked) { cube = new ChordCube(Engine.Engine.Origin, _Constants.CreateHandDistance / 2.0, chord, octave, CurrentInstrument, App.OutputDevice, CurrentChannel); } // give the cube a random colour Random randomGen = new Random(); KnownColor[] names = (KnownColor[])Enum.GetValues(typeof(KnownColor)); KnownColor randomColorName = names[randomGen.Next(names.Length)]; System.Drawing.Color tempColor = System.Drawing.Color.FromKnownColor(randomColorName); System.Windows.Media.Color randomColor = System.Windows.Media.Color.FromArgb(tempColor.A, tempColor.R, tempColor.G, tempColor.B); cube.SolidColorBrush.Color = randomColor; // now set the engine to create mode, and assign this as the cube to be created App.Engine.SetCreateCube(cube); }