public InstrumentChordAction(OutputDevice device, Channel channel, Chord chord, int octave)
     : base() {
     internalDevice = device;
     internalChannel = channel;
     Chord = chord;
     Octave = octave;
 }
示例#2
0
 void PlayChordRun(OutputDevice outputDevice, Chord chord, int millisecondsBetween)
 {
     Pitch previousNote = (Pitch)(-1);
     for (Pitch pitch = Pitch.A0; pitch < Pitch.C8; ++pitch)
     {
         if (chord.Contains(pitch))
         {
             if (previousNote != (Pitch)(-1))
             {
                 outputDevice.SendNoteOff(Channel.Channel1, previousNote, 80);
             }
             outputDevice.SendNoteOn(Channel.Channel1, pitch, 80);
             Thread.Sleep(millisecondsBetween);
             previousNote = pitch;
         }
     }
     if (previousNote != (Pitch)(-1))
     {
         outputDevice.SendNoteOff(Channel.Channel1, previousNote, 80);
     }
 }
示例#3
0
 public void NoteOn(NoteOnMessage msg)
 {
     lock (this)
     {
         List<Pitch> pitches = new List<Pitch>();
         if (playingChords)
         {
             Chord chord = new Chord(msg.Pitch.NotePreferringSharps(),
                 Chord.Patterns[currentChordPattern], 0);
             Pitch p = msg.Pitch;
             for (int i = 0; i < chord.NoteSequence.Length; ++i)
             {
                 p = chord.NoteSequence[i].PitchAtOrAbove(p);
                 pitches.Add(p);
             }
         }
         else
         {
             Scale scale = new Scale(msg.Pitch.NotePreferringSharps(),
                 Scale.Patterns[currentScalePattern]);
             Pitch p = msg.Pitch;
             for (int i = 0; i < scale.NoteSequence.Length; ++i)
             {
                 p = scale.NoteSequence[i].PitchAtOrAbove(p);
                 pitches.Add(p);
             }
             pitches.Add(msg.Pitch + 12);
         }
         lastSequenceForPitch[msg.Pitch] = pitches;
         for (int i = 1; i < pitches.Count; ++i)
         {
             clock.Schedule(new NoteOnMessage(outputDevice, msg.Channel,
                 pitches[i], msg.Velocity, msg.Time + i));
         }
     }
 }
示例#4
0
 /// <summary>
 /// Returns a comma-separated string with the note names of c's NoteSequence.
 /// </summary>
 private static string SequenceString(Chord c)
 {
     string result = "";
     for (int i = 0; i < c.NoteSequence.Length; ++i)
     {
         if (i > 0)
         {
             result += ", ";
         }
         result += c.NoteSequence[i].ToString();
     }
     return result;
 }
示例#5
0
        public void TestAllChords()
        {
            // This test runs over every possible note/pattern/inversion combination over
            // pitches in a range extending beyond the MIDI range, and performs several
            // consistency checks on every one of those chords.

            // For every pitch in the range...
            for (Pitch pitch = (Pitch)(-50); pitch < (Pitch)200; ++pitch)
            {
                // Find the one or two common notes for this pitch.
                List<Note> notes = new List<Note>();
                notes.Add(pitch.NotePreferringSharps());
                if (pitch.NotePreferringFlats() != pitch.NotePreferringSharps())
                {
                    notes.Add(pitch.NotePreferringFlats());
                }
                // For the one or two notes for this pitch...
                foreach (Note note in notes)
                {
                    // For every chord pattern...
                    foreach (ChordPattern pattern in Chord.Patterns)
                    {
                        // For every legal inversion of the pattern...
                        for (int inversion = 0; inversion < pattern.Ascent.Length; ++inversion)
                        {
                            // Construct the chord.
                            Chord c = new Chord(note, pattern, inversion);
                            // Make sure the chord's name, when parsed, is equivalent to the chord.
                            Assert.AreEqual(c, new Chord(c.Name));
                            // Generated a set of pitches based on the chord, starting at or above
                            // the original pitch.
                            Pitch p = pitch;
                            List<Pitch> pitches = new List<Pitch>();
                            foreach (Note n in c.NoteSequence)
                            {
                                p = n.PitchAtOrAbove(p);
                                pitches.Add(p);
                            }
                            Assert.True(Chord.FindMatchingChords(pitches).Contains(c));
                        }
                    }
                }
            }
        }
示例#6
0
        public void Contains()
        {
            Chord cmajor = new Chord("C");
            Pitch[] cmajorPitches = new Pitch[] {
                Pitch.C2, Pitch.E2, Pitch.G2 };
            Pitch[] cmajorNotPitches = new Pitch[] {
                Pitch.CSharp2, Pitch.D2, Pitch.DSharp2, Pitch.F2, Pitch.FSharp2, Pitch.GSharp2,
                Pitch.A2, Pitch.ASharp2 };
            foreach (Pitch p in cmajorPitches)
            {
                Assert.True(cmajor.Contains(p));
            }
            foreach (Pitch p in cmajorNotPitches)
            {
                Assert.False(cmajor.Contains(p));
            }

            Chord bbminor = new Chord("Bbm");
            Pitch[] bbminorPitches = new Pitch[] {
                Pitch.ASharp2, Pitch.CSharp3, Pitch.F3 };
            Pitch[] bbminorNotPitches = new Pitch[] {
                Pitch.B2, Pitch.C3, Pitch.D3, Pitch.DSharp3, Pitch.E3, Pitch.G3,  Pitch.FSharp3,
                Pitch.GSharp3, Pitch.A3 };
            foreach (Pitch p in bbminorPitches)
            {
                Assert.True(bbminor.Contains(p));
            }
            foreach (Pitch p in bbminorNotPitches)
            {
                Assert.False(bbminor.Contains(p));
            }
        }
示例#7
0
 public ChordCube(Point3D center, double radius,
         Chord chord, int octave, Instrument instrument, OutputDevice device, Channel channel)
     : base(center, radius, new InstrumentChordAction(device, channel, chord, octave)) {
 }
        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);
        }