Exemple #1
0
    void CreateInstruments()
    {
        Instrument guitar = new Instrument("rhythmGuitar", gameObject.GetComponent<AudioSource>());

        Chord[] C_Chords = new Chord[6];
        C_Chords[0] = LoadChord("C");
        C_Chords[1] = LoadChord("Dm");
        C_Chords[2] = LoadChord("Em");
        C_Chords[3] = LoadChord("F");
        C_Chords[4] = LoadChord("G");
        C_Chords[5] = LoadChord("Am");

        guitar.AddKey("C", C_Chords);

        Chord[] Am_Chords = new Chord[6];
        Am_Chords[0] = LoadChord("Am");
        Am_Chords[1] = LoadChord("C");
        Am_Chords[2] = LoadChord("Dm");
        Am_Chords[3] = LoadChord("Em");
        Am_Chords[4] = LoadChord("F");
        Am_Chords[5] = LoadChord("G");

        guitar.AddKey("Am", Am_Chords);

        m_Instruments.Add(guitar);
    }
 private void changeSelectedChord(Chord selectedChord)
 {
     chordNameTextBox.Text = selectedChord.FullName;
     chordAbbreviationTextBox.Text = selectedChord.Abbreviation;
     chordIDLabel.Text = "ID: " + selectedChord.ID;
     chordEnabledCheckBox.Checked = selectedChord.Enabled;
     chordFormulaInput.PopulateControl(selectedChord.Formula);
 }
		private void AddTriad()
		{
			Chord chord = new Chord();

			chord.Add(new Note(Note.Letter.C, Note.Accidental.None, Note.Octave.OneLined));
			//chord.Add(new Note(Note.Letter.D, Note.Octave.OneLined));
			chord.Add(new Note(Note.Letter.E, Note.Accidental.None, Note.Octave.OneLined));
			//chord.Add(new Note(Note.Letter.F, Note.Octave.OneLined));
			chord.Add(new Note(Note.Letter.G, Note.Accidental.None, Note.Octave.OneLined));

			score.Add(chord);
		}
Exemple #4
0
        static void ChordTest()
        {
            MusicPlayer player = new MusicPlayer();
            Chord dminor = new Chord(new NoteNames[] { NoteNames.D, NoteNames.F, NoteNames.A }, 4, Durations.wn);
            Chord dmajor = new Chord(new NoteNames[] { NoteNames.G, NoteNames.B, NoteNames.B }, 4, Durations.wn);
            Chord cmajor = new Chord(new NoteNames[] { NoteNames.C, NoteNames.E, NoteNames.G }, 4, Durations.bn);

            HarmonySequence seq = new HarmonySequence();
            seq.AddChord(dminor); seq.AddChord(dmajor); seq.AddChord(cmajor); seq.AddChord(dminor); seq.AddChord(cmajor); seq.AddChord(dminor); seq.AddChord(dmajor); seq.AddChord(cmajor);
            player.Play(seq);
            player.Close();
        }
        private void createNewChord()
        {
            //create the chord
            Chord createdChord = new Chord("New chord", "", "", Guid.NewGuid(), true);
            ChordListItem newChordListItem = new ChordListItem(createdChord);
            chordList.Items.Add(newChordListItem);

            //write to the XML file
            GrassNotesController.LoadedData.WriteNewChord(createdChord);

            //update the GUI
            chordList.SelectedItem = newChordListItem;
            chordNameTextBox.SelectAll();
            chordNameTextBox.Focus();
        }
		private void AddAllTriads()
		{
			List<Key> whiteKeys = keyboard.keys.FindAll(key => key.isWhite);
			for (int k = 0; k < whiteKeys.Count - 4; k++)
			{
				Chord chord = new Chord();

				chord.Add(new Note(whiteKeys[k + 0].note.letter, Note.Accidental.None, whiteKeys[k + 0].note.octave));
				chord.Add(new Note(whiteKeys[k + 2].note.letter, Note.Accidental.None, whiteKeys[k + 2].note.octave));
				chord.Add(new Note(whiteKeys[k + 4].note.letter, Note.Accidental.None, whiteKeys[k + 4].note.octave));

				int u = whiteKeys.Count - 1 - 4 - k;
				chord.Add(new Note(whiteKeys[u + 0].note.letter, Note.Accidental.None, whiteKeys[u + 0].note.octave));
				chord.Add(new Note(whiteKeys[u + 2].note.letter, Note.Accidental.None, whiteKeys[u + 2].note.octave));
				chord.Add(new Note(whiteKeys[u + 4].note.letter, Note.Accidental.None, whiteKeys[u + 4].note.octave));

				score.Add(chord);
			}

			AddBar();
		}
        public bool DeleteChord(Chord chordToDelete)
        {
            //load the root elements
            XDocument loadedDocument = XDocument.Load(GrassNotesController.getPathString());
            XElement rootNode = loadedDocument.Elements().First();
            XElement chordsElement = rootNode.Element("chords");

            if (chordsElement.Elements().Where(q => q.Attribute("id").Value == chordToDelete.ID.ToString()).Count() > 0)
            {
                //create the new chordelement and populate its attributes
                XElement chordElement = chordsElement.Elements().Where(q => q.Attribute("id").Value == chordToDelete.ID.ToString()).First();
                chordElement.Remove();

                //add new chord element to document and save it
                loadedDocument.Save(GrassNotesController.getPathString());
                chords.Remove(chordToDelete.ID);
                return true;
            }
            else
            {
                return false;
            }
        }
Exemple #8
0
 public void getSecondStringFirstFret()
 {
     Assert.AreEqual("A", Chord.GetNoteLetter(1, 0));
 }
 public ChordListItem(Chord chord)
 {
     name = chord.FullName;
     value = chord;
 }
Exemple #10
0
 public static Chord CreateChord(global::System.Guid ID, global::System.Guid measure_Id, short key_Id, int location_X, int location_Y, decimal duration, Audit audit)
 {
     Chord chord = new Chord();
     chord.Id = ID;
     chord.Measure_Id = measure_Id;
     chord.Key_Id = key_Id;
     chord.Location_X = location_X;
     chord.Location_Y = location_Y;
     chord.Duration = duration;
     if ((audit == null))
     {
         throw new global::System.ArgumentNullException("audit");
     }
     chord.Audit = audit;
     return chord;
 }
Exemple #11
0
 public void getThirdStringFirstFret()
 {
     Assert.AreEqual("D", Chord.GetNoteLetter(2, 0));
 }
 public static double[] ConvertChordIntoTrainingInput(Chord chord)
 {
     if (!chord.Notes.Any())
     {
         return null;
     }
     if (chord.Notes.Count == 1)
     {
         var first = chord.Notes.First();
         return new double[] { FromFullNote(first) };
     }
     double[] ret = new double[chord.Notes.Count + 2];
     ret[0] = -1;
     for (int i = 0; i < chord.Notes.Count; i++)
     {
         ret[i + 1] = FromFullNote(chord.Notes[i]);
     }
     ret[chord.Notes.Count + 1] = -1;
     return ret;
 }
Exemple #13
0
        public void PlayChords(Chord[] chords)
        {
            state = 0;
            foreach(Chord c in chords)
            {
                foreach (Note n in c.Notes)
                {
                    midiOut.Send(MidiMessage.StartNote(n.Pitch, c.Velocity, 1).RawData);
                }

                Thread.Sleep((int)(Note.ToRealDuration(c.Duration) * 1000));
                foreach (Note n in c.Notes)
                {
                    midiOut.Send(MidiMessage.StopNote(n.Pitch, 0, 1).RawData);
                }
            }
        }
Exemple #14
0
 public Command GetChord(Chord chord)
 {
     if (this.chords.ContainsKey(chord))
         return this.chords[chord];
     else
     {
         Command cmd = new Command();
         this.chords.Add(chord, cmd);
         return cmd;
     }
 }
Exemple #15
0
 public ChordEvent()
 {
     Chord = new Chord();
 }
Exemple #16
0
        void IUpdateableComponent.Update(float dt)
        {
            KeyboardState keyboard = this.main.KeyboardState;
            Keys[] unfilteredKeys = keyboard.GetPressedKeys();
            Keys[] keys = unfilteredKeys.Except(this.lastPressedKeys).ToArray();
            if (this.StringPropertyLocked && unfilteredKeys.Length > 0)
            {
                if (this.selectedStringNavigateInterval > 0.1f)
                {
                    if (unfilteredKeys.Contains(Keys.Back))
                    {
                        this.selectedStringNavigateInterval = 0.0f;
                        if (this.selectedStringValue.Length > 0 && this.selectedStringIndex > 0)
                        {
                            this.selectedStringValue = this.selectedStringValue.Remove(this.selectedStringIndex - 1, 1);
                            this.selectedStringIndex--;
                        }
                    }
                    else if (unfilteredKeys.Contains(Keys.Delete))
                    {
                        this.selectedStringNavigateInterval = 0.0f;
                        if (this.selectedStringIndex < this.selectedStringValue.Length)
                            this.selectedStringValue = this.selectedStringValue.Remove(this.selectedStringIndex, 1);
                    }
                    else if (unfilteredKeys.Contains(Keys.Down))
                    {
                        this.selectedStringNavigateInterval = 0.0f;
                        if (this.selectedStringValue.Length > 0 && this.selectedStringAllowMultiline)
                        {
                            int index = this.selectedStringValue.IndexOf('\n', this.selectedStringIndex + 1);
                            if (index == -1)
                                this.selectedStringIndex = this.selectedStringValue.Length;
                            else
                                this.selectedStringIndex = index;
                        }
                    }
                    else if (unfilteredKeys.Contains(Keys.Up))
                    {
                        this.selectedStringNavigateInterval = 0.0f;
                        if (this.selectedStringValue.Length > 0 && this.selectedStringAllowMultiline)
                        {
                            int index = this.selectedStringValue.Substring(0, Math.Max(0, this.selectedStringIndex - 1)).LastIndexOf('\n');
                            if (index == -1)
                                this.selectedStringIndex = 0;
                            else
                                this.selectedStringIndex = index;
                        }
                    }
                    else if (unfilteredKeys.Contains(Keys.Left) || unfilteredKeys.Contains(Keys.Right))
                    {
                        this.selectedStringNavigateInterval = 0.0f;
                        if (this.selectedStringValue.Length > 0)
                        {
                            this.selectedStringIndex += unfilteredKeys.Contains(Keys.Right) ? 1 : -1;
                            if (this.selectedStringIndex < 0)
                                this.selectedStringIndex = Math.Max(0, this.selectedStringValue.Length);
                            else if (this.selectedStringIndex > this.selectedStringValue.Length)
                                this.selectedStringIndex = 0;
                        }
                    }
                }

                if (unfilteredKeys.Contains(Keys.Tab) || (unfilteredKeys.Contains(Keys.Enter) && !this.selectedStringAllowMultiline))
                {
                    this.commitStringProperty();
                    return;
                }
                else if (unfilteredKeys.Contains(Keys.Escape) && !this.selectedStringAllowEscape)
                {
                    this.revertStringProperty();
                    return;
                }

                bool caps = unfilteredKeys.Contains(Keys.LeftShift) || unfilteredKeys.Contains(Keys.RightShift);
                foreach (Keys key in keys)
                {
                    if (!EditorUI.ignoredKeys.Contains(key))
                    {
                        this.selectedStringIndex++;
                        Chord chord = new Chord { Keys = key, Shift = caps };
                        if (EditorUI.inputKeyMappings.ContainsKey(chord))
                            this.selectedStringValue = this.selectedStringValue.Insert(this.selectedStringIndex - 1, EditorUI.inputKeyMappings[chord]);
                        else
                            this.selectedStringValue = this.selectedStringValue.Insert(this.selectedStringIndex - 1, caps ? key.ToString().ToUpper() : key.ToString().ToLower());
                    }
                }

                this.selectedStringDisplayProperty.Value = this.selectedStringValue.Insert(this.selectedStringIndex, "_");
            }
            this.lastPressedKeys = unfilteredKeys;
            this.selectedStringNavigateInterval += dt;
        }
 public static double Calculate(Chord longestChord, Chord longestPerpendicularChord)
 {
     return longestPerpendicularChord.Length / longestChord.Length;
 }
        private void saveChord()
        {
            //create the chord object for the new chord
            string newChordName = chordNameTextBox.Text.Trim();
            string newChordAbbreviation = chordAbbreviationTextBox.Text.Trim();
            List<Interval> newChordFormula = chordFormulaInput.GetFormula().ToList();
            Guid updatedChordID = ((ChordListItem)chordList.SelectedItem).Value.ID;
            bool newChordenabled = chordEnabledCheckBox.Checked;
            Chord updatedChord = new Chord(newChordName, newChordAbbreviation, newChordFormula, updatedChordID, newChordenabled);

            //write the new chord to XMl and to the data object
            GrassNotesController.LoadedData.UpdateChord(updatedChord);

            //update the GUI
            ((ChordListItem)chordList.SelectedItem).UpdateItem(updatedChord);
            chordList.RefreshItem(chordList.SelectedIndex);
        }
Exemple #19
0
 public void AddChord(int position, Chord chord, byte volume)
 {
     lastChord = chord;
     foreach (byte note in chord.Notes)
     {
         AddNote(position, note, volume);
     }
 }
 public override Chord Transform(Chord baseMelody)
 {
     throw new NotImplementedException();
 }
Exemple #21
0
 public void setFirstChord(Chord firstChord)
 {
     currentChord = firstChord;
 }
Exemple #22
0
        public virtual void Update(float elapsedTime)
        {
            if (!main.IsActive)
                return;

            KeyboardState keyboard = this.main.KeyboardState;

            Keys[] keys = keyboard.GetPressedKeys();
            if (keys.Length > 0 && this.nextInputListeners.Count > 0)
                this.notifyNextInputListeners(new PCInputBinding { Key = keys[0] });

            foreach (KeyValuePair<Keys, Property<bool>> pair in this.keyProperties)
            {
                bool newValue = keyboard.IsKeyDown(pair.Key);
                if (newValue != pair.Value.Value)
                {
                    pair.Value.Value = newValue;
                    if (!this.preventKeyDownEvents)
                    {
                        if (newValue)
                        {
                            Command command;
                            if (keyDownCommands.TryGetValue(pair.Key, out command))
                                command.Execute();
                        }
                        else
                        {
                            Command command;
                            if (keyUpCommands.TryGetValue(pair.Key, out command))
                                command.Execute();
                        }
                    }
                }
            }

            if (!this.chordActivated && !this.preventKeyDownEvents)
            {
                if (keys.Length == 2)
                {
                    Chord chord = new Chord();
                    if (keys[1] == Keys.LeftAlt || keys[1] == Keys.LeftControl || keys[1] == Keys.LeftShift || keys[1] == Keys.LeftWindows
                        || keys[1] == Keys.RightAlt || keys[1] == Keys.RightControl || keys[1] == Keys.RightShift || keys[1] == Keys.RightWindows)
                    {
                        chord.Modifier = keys[1];
                        chord.Key = keys[0];
                    }
                    else
                    {
                        chord.Modifier = keys[0];
                        chord.Key = keys[1];
                    }
                    if (this.chords.ContainsKey(chord))
                    {
                        this.chords[chord].Execute();
                        this.chordActivated = true;
                    }
                }
            }
            else if (keyboard.GetPressedKeys().Length == 0)
                this.chordActivated = false;

            MouseState mouse = this.main.MouseState;
            this.handleMouse();

            bool newLeftMouseButton = mouse.LeftButton == ButtonState.Pressed;
            if (newLeftMouseButton != this.LeftMouseButton)
            {
                this.LeftMouseButton.Value = newLeftMouseButton;
                if (!this.preventKeyDownEvents)
                {
                    if (newLeftMouseButton)
                    {
                        if (this.nextInputListeners.Count > 0)
                            this.notifyNextInputListeners(new PCInputBinding { MouseButton = MouseButton.LeftMouseButton });
                        this.LeftMouseButtonDown.Execute();
                    }
                    else
                        this.LeftMouseButtonUp.Execute();
                }
            }

            bool newMiddleMouseButton = mouse.MiddleButton == ButtonState.Pressed;
            if (newMiddleMouseButton != this.MiddleMouseButton)
            {
                this.MiddleMouseButton.Value = newMiddleMouseButton;
                if (!this.preventKeyDownEvents)
                {
                    if (newMiddleMouseButton)
                    {
                        if (this.nextInputListeners.Count > 0)
                            this.notifyNextInputListeners(new PCInputBinding { MouseButton = MouseButton.MiddleMouseButton });
                        this.MiddleMouseButtonDown.Execute();
                    }
                    else
                        this.MiddleMouseButtonUp.Execute();
                }
            }

            bool newRightMouseButton = mouse.RightButton == ButtonState.Pressed;
            if (newRightMouseButton != this.RightMouseButton)
            {
                this.RightMouseButton.Value = newRightMouseButton;
                if (!this.preventKeyDownEvents)
                {
                    if (newRightMouseButton)
                    {
                        if (this.nextInputListeners.Count > 0)
                            this.notifyNextInputListeners(new PCInputBinding { MouseButton = MouseButton.RightMouseButton });
                        this.RightMouseButtonDown.Execute();
                    }
                    else
                        this.RightMouseButtonUp.Execute();
                }
            }

            int newScrollWheel = mouse.ScrollWheelValue;
            int oldScrollWheel = this.ScrollWheel;
            if (newScrollWheel != oldScrollWheel)
            {
                this.ScrollWheel.Value = newScrollWheel;
                if (!this.preventKeyDownEvents)
                    this.MouseScrolled.Execute(newScrollWheel > oldScrollWheel ? 1 : -1);
            }
            this.preventKeyDownEvents = false;
        }
Exemple #23
0
 public void Create(Chord chord)
 {
     this.chord = chord;
     Debug.Log(chord.root);
 }
        private string SingleChord(Chord c)
        {
            if (c == null || c.Notes == null || c.Notes.Count == 0)
            {
                return string.Empty;
            }
            if (c.Notes.Count == 1)
            {
                return c.Notes.First().Note.ToString() + this.OctavePrefix(c.Notes.First());
            }
            StringBuilder builder = new StringBuilder();

            if (!this.NoteByNote)
            {
                builder.Append("<");
                foreach (var item in c.Notes)
                {
                    builder.Append(this.PureNoteString(item) + this.OctavePrefix(item) + " ");
                }
                builder.Append(">");
            }
            else
            {
                foreach (var item in c.Notes)
                {
                    lock (this)
                    {
                        builder.Append(this.PureNoteString(item) + this.OctavePrefix(item) + " ");
                    }
                }
            }
            return builder.ToString();
        }
Exemple #25
0
    private void readNewChord(Chord chord)
    {
        /*Read new-style (GP4) chord diagram.
         *
         * New-style chord diagram is read as follows:
         *
         * - Sharp: :ref:`bool`. If true, display all semitones as sharps,
         * otherwise display as flats.
         *
         * - Blank space, 3 :ref:`Bytes <byte>`.
         *
         * - Root: :ref:`int`. Values are:
         *
         * -1 for customized chords
         *  0: C
         *  1: C#
         * ...
         *
         * - Type: :ref:`int`. Determines the chord type as followed. See
         * :class:`guitarpro.models.ChordType` for mapping.
         *
         * - Chord extension: :ref:`int`. See
         * :class:`guitarpro.models.ChordExtension` for mapping.
         *
         * - Bass note: :ref:`int`. Lowest note of chord as in *C/Am*.
         *
         * - Tonality: :ref:`int`. See
         * :class:`guitarpro.models.ChordAlteration` for mapping.
         *
         * - Add: :ref:`bool`. Determines if an "add" (added note) is
         * present in the chord.
         *
         * - Name: :ref:`byte-size-string`. Max length is 22.
         *
         * - Fifth alteration: :ref:`int`. Maps to
         * :class:`guitarpro.models.ChordAlteration`.
         *
         * - Ninth alteration: :ref:`int`. Maps to
         * :class:`guitarpro.models.ChordAlteration`.
         *
         * - Eleventh alteration: :ref:`int`. Maps to
         * :class:`guitarpro.models.ChordAlteration`.
         *
         * - List of frets: 6 :ref:`Ints <int>`. Fret values are saved as
         * in default format.
         *
         * - Count of barres: :ref:`int`. Maximum count is 2.
         *
         * - Barre frets: 2 :ref:`Ints <int>`.
         *
         * - Barre start strings: 2 :ref:`Ints <int>`.
         *
         * - Barre end string: 2 :ref:`Ints <int>`.
         *
         * - Omissions: 7 :ref:`Bools <bool>`. If the value is true then
         * note is played in chord.
         *
         * - Blank space, 1 :ref:`byte`.*/

        chord.sharp = GPBase.readBool()[0];
        var intonation = chord.sharp ? "sharp" : "flat";

        GPBase.skip(3);
        chord.root      = new PitchClass(GPBase.readInt()[0], -1, "", intonation);
        chord.type      = (ChordType)GPBase.readInt()[0];
        chord.extension = (ChordExtension)GPBase.readInt()[0];
        chord.bass      = new PitchClass(GPBase.readInt()[0], -1, "", intonation);
        chord.tonality  = (ChordAlteration)GPBase.readInt()[0];
        chord.add       = GPBase.readBool()[0];
        chord.name      = GPBase.readByteSizeString(22);
        chord.fifth     = (ChordAlteration)GPBase.readInt()[0];
        chord.ninth     = (ChordAlteration)GPBase.readInt()[0];
        chord.eleventh  = (ChordAlteration)GPBase.readInt()[0];
        chord.firstFret = GPBase.readInt()[0];
        for (int i = 0; i < 6; i++)
        {
            var fret = GPBase.readInt()[0];
            if (i < chord.strings.Length)
            {
                chord.strings[i] = fret;
            }
        }
        chord.barres.Clear();
        var barresCount = GPBase.readInt()[0];
        var barreFrets  = GPBase.readInt(2);
        var barreStarts = GPBase.readInt(2);
        var barreEnds   = GPBase.readInt(2);

        for (int x = 0; x < Math.Min(2, barresCount); x++)
        {
            var barre = new Barre(barreFrets[x], barreStarts[x], barreEnds[x]);
            chord.barres.Add(barre);
        }
        chord.omissions = GPBase.readBool(7);
        GPBase.skip(1);
    }
        public void Append(Chord chord)
        {
            chord.NullCheck();

            this.innerChords.Add(chord);
        }
Exemple #27
0
        int ExportOrFindBeat(Chord chord)
        {
            var beat = new Beat();
            beat.Id = gpif.Beats.Count;
            foreach (var note in chord.Notes)
            {
                int id = ExportOrFindNote(note.Value);
                beat.Notes.Add(id);
            }
            // there seem to be a few accidental ties set in the Rocksmith XMLs
            // so unset the tie status on any strings that weren't in the current chord.
            for (int i = 0; i < 6; ++i)
            {
                if (!chord.Notes.ContainsKey(i))
                    link[i] = false;
            }

            // should we display a strum hint?
            if (chord.BrushDirection != Chord.BrushType.None)
            {
                var brushProp = new Property() { Name = "Brush" };
                if (chord.BrushDirection == Chord.BrushType.Down)
                    brushProp.Direction = "Down";
                else
                    brushProp.Direction = "Up";
                if (beat.Properties == null)
                    beat.Properties = new List<Property>();
                beat.Properties.Add(brushProp);
            }

            // tremolo picking
            if (chord.Tremolo)
            {
                // 32nd notes tremolo picking (should be appropriate)
                beat.Tremolo = "1/8";
            }

            // slap/pop notes
            if (chord.Slapped)
            {
                if (beat.Properties == null)
                    beat.Properties = new List<Property>();
                beat.Properties.Add(new Property() { Name = "Slapped", Enable = new Property.EnableType() });
            }
            if (chord.Popped)
            {
                if (beat.Properties == null)
                    beat.Properties = new List<Property>();
                beat.Properties.Add(new Property() { Name = "Popped", Enable = new Property.EnableType() });
            }

            // construct rhythm
            var rhythm = new Rhythm();
            rhythm.Id = gpif.Rhythms.Count;
            switch (chord.Duration)
            {
                case 192:
                    rhythm.NoteValue = "Whole";
                    break;
                case 168:  // should avoid this, split note instead (TODO)
                    rhythm.NoteValue = "Half";
                    rhythm.AugmentationDot = new Rhythm.Dot() { Count = 2 };
                    break;
                case 144:
                    rhythm.NoteValue = "Half";
                    rhythm.AugmentationDot = new Rhythm.Dot() { Count = 1 };
                    break;
                case 96:
                    rhythm.NoteValue = "Half";
                    break;
                case 84:  // should avoid this, split note instead (TODO)
                    rhythm.NoteValue = "Quarter";
                    rhythm.AugmentationDot = new Rhythm.Dot() { Count = 2 };
                    break;
                case 72:
                    rhythm.NoteValue = "Quarter";
                    rhythm.AugmentationDot = new Rhythm.Dot() { Count = 1 };
                    break;
                case 48:
                    rhythm.NoteValue = "Quarter";
                    break;
                case 36:
                    rhythm.NoteValue = "Eighth";
                    rhythm.AugmentationDot = new Rhythm.Dot() { Count = 1 };
                    break;
                case 32:
                    rhythm.NoteValue = "Quarter";
                    rhythm.PrimaryTuplet = new Rhythm.Tuplet() { Den = 2, Num = 3 };
                    break;
                case 24:
                    rhythm.NoteValue = "Eighth";
                    break;
                case 18:
                    rhythm.NoteValue = "16th";
                    rhythm.AugmentationDot = new Rhythm.Dot() { Count = 1 };
                    break;
                case 16:
                    rhythm.NoteValue = "Eighth";
                    rhythm.PrimaryTuplet = new Rhythm.Tuplet() { Den = 2, Num = 3 };
                    break;
                case 12:
                    rhythm.NoteValue = "16th";
                    break;
                case 9:
                    rhythm.NoteValue = "32nd";
                    rhythm.AugmentationDot = new Rhythm.Dot() { Count = 1 };
                    break;
                case 8:
                    rhythm.NoteValue = "16th";
                    rhythm.PrimaryTuplet = new Rhythm.Tuplet() { Den = 2, Num = 3 };
                    break;
                case 6:
                    rhythm.NoteValue = "32nd";
                    break;
                case 4:
                    rhythm.NoteValue = "32nd";
                    rhythm.PrimaryTuplet = new Rhythm.Tuplet() { Den = 2, Num = 3 };
                    break;
                case 3:
                    rhythm.NoteValue = "64th";
                    break;
                case 2:
                    rhythm.NoteValue = "64th";
                    rhythm.PrimaryTuplet = new Rhythm.Tuplet() { Den = 2, Num = 3 };
                    break;
                case 1:
                    rhythm.NoteValue = "128th";
                    rhythm.PrimaryTuplet = new Rhythm.Tuplet() { Den = 2, Num = 3 };
                    break;
                default:
                    Console.WriteLine("  Warning: Rhythm Duration {0} not handled, defaulting to quarter note.", chord.Duration);
                    rhythm.NoteValue = "Quarter";
                    break;
            }
            // see if this rhythm already exists, otherwise add
            var searchRhythm = gpif.Rhythms.Find(x => x.Equals(rhythm));
            if (searchRhythm != null)
                rhythm = searchRhythm;
            else
                gpif.Rhythms.Add(rhythm);

            beat.Rhythm.Ref = rhythm.Id;

            // should we display a chord name?
            if (chord.ChordId != -1 && chord.ChordId != prevChordId)
            {
                beat.Chord = chord.ChordId.ToString();
            }
            prevChordId = chord.ChordId;

            if (chord.Section != null)
                beat.FreeText = chord.Section;

            // see if this beat already exists, otherwise add
            var searchBeat = gpif.Beats.Find(x => x.Equals(beat));
            if (searchBeat != null)
                beat = searchBeat;
            else
                gpif.Beats.Add(beat);

            return beat.Id;
        }
Exemple #28
0
 public void getFirstStringTwelfthFret()
 {
     Assert.AreEqual("E", Chord.GetNoteLetter(0, 12));
 }
Exemple #29
0
 public void AddToChords(Chord chord)
 {
     base.AddObject("Chords", chord);
 }
Exemple #30
0
        public void getIntervalRootAnotherChord2()
        {
            Chord c = new Chord("D#");

            Assert.AreEqual("r", c.getIntervalFromRootNote("D#"));
        }
Exemple #31
0
 public void getFourthStringTwelfthFret()
 {
     Assert.AreEqual("G", Chord.GetNoteLetter(3, 12));
 }
Exemple #32
0
        public void getIntervalp5()
        {
            Chord c = new Chord("C+5");

            Assert.AreEqual("+5", c.getIntervalFromRootNote("G#"));
        }
Exemple #33
0
 public void getThirdStringTwelfthFret()
 {
     Assert.AreEqual("D", Chord.GetNoteLetter(2, 12));
 }
Exemple #34
0
 public void getSixthStringFirstFret()
 {
     Assert.AreEqual("E", Chord.GetNoteLetter(5, 0));
 }
Exemple #35
0
 public void getSecondStringTwelfthFret()
 {
     Assert.AreEqual("A", Chord.GetNoteLetter(1, 12));
 }
 public void UpdateItem(Chord chord)
 {
     name = chord.FullName;
     value = chord;
 }
Exemple #37
0
        public void getRootNoteTestb()
        {
            Chord c = new Chord("Cb");

            Assert.AreEqual("Cb", c.getRootNote());
        }
Exemple #38
0
        public static ChordProgression ChordGen(Scale Scale, List <int> ProgPattern, List <int> ColorPattern, int duration = 1, int Root = 1, int Offset1 = 2, int Offset2 = 4)
        {
            ChordProgression ChordList = new ChordProgression();
            ChordProgression PureList  = new ChordProgression();
            int counter = 0;

            //Use Progression Pattern
            if (ProgPattern != null)
            {
                foreach (var chordNum in ProgPattern)
                {
                    var scaleIndex = chordNum - 1;
                    var root       = Scale.Steps[scaleIndex % Scale.Steps.Count];

                    //Do we need to add an octave?
                    bool octPlus = (scaleIndex + Offset1) >= Scale.Steps.Count;
                    var  c2      = Scale.Steps[(scaleIndex + Offset1) % Scale.Steps.Count];
                    var  third   = octPlus ? c2 + Scale.Divisions : c2;

                    octPlus = (scaleIndex + Offset2) >= Scale.Steps.Count;
                    var c3    = Scale.Steps[(scaleIndex + Offset2) % Scale.Steps.Count];
                    var fifth = octPlus ? c3 + Scale.Divisions : c3;

                    var chord = new Chord(
                        root,
                        third,
                        fifth
                        );

                    if (ColorPattern != null && ColorPattern.Count > 0)
                    {
                        var colorNum = ColorPattern[counter % ColorPattern.Count];

                        if (colorNum > Scale.Steps.Count)
                        {
                            chord.Notes.Add(Scale.Steps[(scaleIndex + (colorNum - 1)) % Scale.Steps.Count] + Scale.Divisions);
                        }
                        else
                        {
                            chord.Notes.Add(Scale.Steps[(scaleIndex + (colorNum - 1)) % Scale.Steps.Count]);
                        }
                    }

                    PureList.Chords.Add(chord);

                    counter++;
                }
            }
            else //Otherwise default to all scale roots
            {
                for (int step = 0; step < Scale.Steps.Count; step++)
                {
                    var root = Scale.Steps[step % Scale.Steps.Count];

                    //Do we need to add an octave?
                    bool octPlus = (step + Offset1) >= Scale.Steps.Count;
                    var  c2      = Scale.Steps[(step + Offset1) % Scale.Steps.Count];
                    var  third   = octPlus ? c2 + Scale.Divisions : c2;

                    octPlus = (step + Offset2) >= Scale.Steps.Count;
                    var c3    = Scale.Steps[(step + Offset2) % Scale.Steps.Count];
                    var fifth = octPlus ? c3 + Scale.Divisions : c3;

                    var chord = new Chord(
                        root,
                        third,
                        fifth
                        );

                    if (ColorPattern != null && ColorPattern.Count > 0)
                    {
                        var colorNum = ColorPattern[counter % ColorPattern.Count];

                        if (colorNum > Scale.Steps.Count)
                        {
                            chord.Notes.Add(Scale.Steps[(step + colorNum) % Scale.Steps.Count] + Scale.Divisions);
                        }
                        else
                        {
                            chord.Notes.Add(Scale.Steps[(step + colorNum) % Scale.Steps.Count]);
                        }
                    }

                    PureList.Chords.Add(chord);

                    counter++;
                }
            }

            for (int i = 0; i < duration; i++)
            {
                ChordList.Chords.AddRange(PureList.Chords);
            }

            return(ChordList);
        }
Exemple #39
0
        public void getIntervalm6()
        {
            Chord c = new Chord("C");

            Assert.AreEqual("m6", c.getIntervalFromRootNote("G#"));
        }
Exemple #40
0
 protected bool Equals(Chord other)
 {
     return(string.Equals(Name, other.Name) && Kind == other.Kind && Equals(ChordPitches, other.ChordPitches));
 }
Exemple #41
0
        public void getIntervalp5bang()
        {
            Chord c = new Chord("C5#");

            Assert.AreEqual("5#", c.getIntervalFromRootNote("G#"));
        }
Exemple #42
0
        private static Chord PredictChordRandom(List <Pitch> pitches, Key key)
        {
            List <Chord> candidates = new List <Chord>()
            {
                C, Dm, Em, F, G, Am, Bdim
            };

            int[] candCount = new int[candidates.Count];

            //If a
            foreach (var p in pitches)
            {
                for (int i = 0; i < candidates.Count; i++)
                {
                    if (candidates[i].Contains(p))
                    {
                        candCount[i] += 1;
                    }
                }
            }

            int        max         = 0;
            List <int> chordsAtMax = new List <int>();

            for (int i = 0; i < candCount.Length; i++)
            {
                if (candCount[i] > candCount[max])
                {
                    max = i;

                    chordsAtMax = new List <int>();
                    chordsAtMax.Add(i);
                }
                else if (candCount[i] == candCount[max])
                {
                    chordsAtMax.Add(i);
                }
            }

            Chord chord = null;

            if (chordsAtMax.Count == 1)
            {
                chord = candidates[max];
            }
            else if (chordsAtMax.Count > 1)
            {
                Random rand  = new Random();
                int    index = chordsAtMax[rand.Next(chordsAtMax.Count)];

                chord = candidates[index];
            }

            Console.WriteLine();
            Console.Write("\t");
            Console.Write(@"{0}, ", chord);

            foreach (var p in pitches)
            {
                Console.Write(@"{0} ", p);
            }

            return(chord);
        }
Exemple #43
0
        private Chord GetChord(Note n)
        {
            int[] pitches;
            if(n.NotePitch == (int)NoteNames.A || n.NotePitch == (int)NoteNames.As )
            {
                int i = r.Next(0, a.Length);
                pitches = a[i];
            }
            else if(n.NotePitch == (int)NoteNames.B)
            {
                int i = r.Next(0, b.Length);
                pitches = b[i];
            }
            else if(n.NotePitch == (int)NoteNames.C || n.NotePitch == (int)NoteNames.Cs )
            {
                int i = r.Next(0, c.Length);
                pitches = c[i];
            }
            else if(n.NotePitch == (int)NoteNames.D || n.NotePitch == (int)NoteNames.Ds )
            {
                int i = r.Next(0, d.Length);
                pitches = d[i];
            }
            else if(n.NotePitch == (int)NoteNames.E)
            {
                int i = r.Next(0, e.Length);
                pitches = e[i];
            }
            else if(n.NotePitch == (int)NoteNames.F || n.NotePitch == (int)NoteNames.Fs )
            {
                int i = r.Next(0, f.Length);
                pitches = f[i];
            }
            else if(n.NotePitch == (int)NoteNames.G || n.NotePitch == (int)NoteNames.GS )
            {
                int i = r.Next(0, g.Length);
                pitches = g[i];
            }
            else
            {
                int i = r.Next(0, a.Length);
                pitches = a[i];
            }

            for (int i = 0; i < pitches.Length; i++)
                pitches[i] = 12 * n.Octave + pitches[i];
            Chord ch = new Chord(pitches, n.Duration, n.Velocity/2);
            return ch;
        }
Exemple #44
0
        public void ReadChord(Beat beat)
        {
            var chord   = new Chord();
            var chordId = Platform.Platform.NewGuid();

            if (_versionNumber >= 500)
            {
                Data.Skip(17);
                chord.Name = Data.GpReadStringByteLength(21, _encoding);
                Data.Skip(4);
                chord.FirstFret = Data.ReadInt32LE();
                for (int i = 0; i < 7; i++)
                {
                    var fret = Data.ReadInt32LE();
                    if (i < beat.Voice.Bar.Staff.Tuning.Length)
                    {
                        chord.Strings.Add(fret);
                    }
                }

                var numberOfBarres = Data.ReadByte();
                var barreFrets     = new byte[5];
                Data.Read(barreFrets, 0, barreFrets.Length);
                for (int i = 0; i < numberOfBarres; i++)
                {
                    chord.BarreFrets.Add(barreFrets[i]);
                }

                Data.Skip(26);
            }
            else
            {
                if (Data.ReadByte() != 0) // mode1?
                {
                    // gp4
                    if (_versionNumber >= 400)
                    {
                        // Sharp (1)
                        // Unused (3)
                        // Root (1)
                        // Major/Minor (1)
                        // Nin,Eleven or Thirteen (1)
                        // Bass (4)
                        // Diminished/Augmented (4)
                        // Add (1)
                        Data.Skip(16);
                        chord.Name = Data.GpReadStringByteLength(21, _encoding);
                        // Unused (2)
                        // Fifth (1)
                        // Ninth (1)
                        // Eleventh (1)
                        Data.Skip(4);
                        chord.FirstFret = (Data.ReadInt32LE());
                        for (int i = 0; i < 7; i++)
                        {
                            var fret = Data.ReadInt32LE();
                            if (i < beat.Voice.Bar.Staff.Tuning.Length)
                            {
                                chord.Strings.Add(fret);
                            }
                        }

                        var numberOfBarres = Data.ReadByte();
                        var barreFrets     = new byte[5];
                        Data.Read(barreFrets, 0, barreFrets.Length);
                        for (int i = 0; i < numberOfBarres; i++)
                        {
                            chord.BarreFrets.Add(barreFrets[i]);
                        }

                        // Barree end (5)
                        // Omission1,3,5,7,9,11,13 (7)
                        // Unused (1)
                        // Fingering (7)
                        // Show Diagram Fingering (1)
                        // ??
                        Data.Skip(26);
                    }
                    else
                    {
                        // unknown
                        Data.Skip(25);
                        chord.Name      = Data.GpReadStringByteLength(34, _encoding);
                        chord.FirstFret = Data.ReadInt32LE();
                        for (int i = 0; i < 6; i++)
                        {
                            var fret = Data.ReadInt32LE();
                            if (i < beat.Voice.Bar.Staff.Tuning.Length)
                            {
                                chord.Strings.Add(fret);
                            }
                        }
                        // unknown
                        Data.Skip(36);
                    }
                }
                else
                {
                    int strings = _versionNumber >= 406 ? 7 : 6;

                    chord.Name      = Data.GpReadStringIntByte(_encoding);
                    chord.FirstFret = Data.ReadInt32LE();
                    if (chord.FirstFret > 0)
                    {
                        for (int i = 0; i < strings; i++)
                        {
                            var fret = Data.ReadInt32LE();
                            if (i < beat.Voice.Bar.Staff.Tuning.Length)
                            {
                                chord.Strings.Add(fret);
                            }
                        }
                    }
                }
            }


            if (!string.IsNullOrEmpty(chord.Name))
            {
                beat.ChordId = chordId;
                beat.Voice.Bar.Staff.Chords[beat.ChordId] = chord;
            }
        }
 private static void PrepareChordsOctave(InstrumentType instrument, Chord chord)
 {
     instrument.GoToOctave(chord.Notes.First());
 }
 public void playChord(Chord chordToPlay, int rootNote)
 {
 }
Exemple #47
0
 public void OnChordParsed(Chord chord)
 {
     ChordParsed?.Invoke(this, new ChordParsedEventArgs {
         Chord = chord
     });
 }
 public void playChord(Chord chordToPlay, double delay, int inversion, int rootNote)
 {
 }
Exemple #49
0
        /// <summary>
        /// Loads a Harmony Sequence though
        /// </summary>
        /// <param name="f"></param>
        /// <returns></returns>
        public static Composition LoadMidiType1(MidiFile f)
        {
            Composition comp = new Composition();
            int c = 1;
            foreach(var trackEvents in f.Events)
            {
                Track t = new Track();

                t.Channel = (byte)c++;
                TempoEvent tempo = new TempoEvent((int)(Note.ToRealDuration((int)Durations.qn, 60) * 1000000), 0);
                HarmonySequence seq = new HarmonySequence();
                long lastAbsTime = -1;

                List<int> chordNotes = new List<int>(); int chordDuration = 0;
                PatchNames instr = (PatchNames)9999;

                bool add = true;
                foreach(var e in trackEvents)
                {
                    if (e as TempoEvent != null)
                    {
                        tempo = (TempoEvent)e;
                    }
                    if (e as PatchChangeEvent != null)
                    {
                        var p = e as PatchChangeEvent;
                        t.Instrument = (PatchNames)p.Patch;

                        if(t.Instrument == instr)
                        {
                            break;
                        }
                        instr = t.Instrument;
                        /*if(t.Duration < 1)
                        {
                            foreach(var t_ in comp.Tracks)
                                if(t_.Instrument == (PatchNames)p.Patch)
                                {
                                    t = t_;
                                    seq = t_.GetMainSequence() as HarmonySequence;
                                    add = false;
                                    break;
                                }
                        }*/
                    }
                    NoteOnEvent on = e as NoteOnEvent;

                    if (on != null && on.OffEvent != null)
                    {
                        int newDuration = Note.ToNoteLength(on.NoteLength, f.DeltaTicksPerQuarterNote, tempo.Tempo);

                        if (on.AbsoluteTime == lastAbsTime && chordDuration==newDuration)//skip chords
                        {
                            chordNotes.Add(on.NoteNumber);
                        }
                        else
                        {
                            Chord lastChord = new Chord(chordNotes.ToArray(), chordDuration);
                            chordNotes.Clear(); chordDuration = 0;
                            seq.AddChord(lastChord);

                            chordNotes.Add(on.NoteNumber);
                        }

                        chordDuration = newDuration;
                        lastAbsTime = on.AbsoluteTime;
                    }
                }
                if(chordNotes.Count > 0)
                {
                    Chord lastChord = new Chord(chordNotes.ToArray(), chordDuration);
                    chordNotes.Clear(); chordDuration = 0;
                    seq.AddChord(lastChord);
                }

                t.AddSequence(seq);
                if (!comp.Tracks.Contains(t) && t.Duration > 0 && add)
                    comp.Add(t);
            }

            return comp;
        }
Exemple #50
0
            public void Get_NoNotes()
            {
                var chord = new Chord();

                Assert.Throws <InvalidOperationException>(() => GetPropertyValue(_chordPropertySelector, chord));
            }
Exemple #51
0
        public virtual void Update(float elapsedTime)
        {
            if (!this.main.IsActive)
            {
                return;
            }

            if (!this.main.LastActive)
            {
                if (this.main.MouseState.Value.LeftButton == ButtonState.Pressed)
                {
                    this.temporarilyIgnoreLMB = true;
                }
            }

            KeyboardState keyboard = this.main.KeyboardState;

            Keys[] keys = keyboard.GetPressedKeys();
            if (keys.Length > 0 && this.nextInputListeners.Count > 0)
            {
                this.notifyNextInputListeners(new PCInputBinding {
                    Key = keys[0]
                });
            }

            if (this.AnyInputDown.Bindings.Count > 0)
            {
                Keys[] lastKeys = this.main.LastKeyboardState.Value.GetPressedKeys();
                for (int i = 0; i < keys.Length; i++)
                {
                    if (!lastKeys.Contains(keys[i]))
                    {
                        this.AnyInputDown.Execute(new PCInputBinding {
                            Key = keys[i]
                        });
                    }
                }
            }

            foreach (KeyValuePair <Keys, Property <bool> > pair in this.keyProperties)
            {
                bool newValue = keyboard.IsKeyDown(pair.Key);
                if (newValue != pair.Value.Value)
                {
                    pair.Value.Value = newValue;
                    if (!this.preventKeyDownEvents)
                    {
                        if (newValue)
                        {
                            Command command;
                            if (this.keyDownCommands.TryGetValue(pair.Key, out command))
                            {
                                command.Execute();
                            }
                        }
                        else
                        {
                            Command command;
                            if (this.keyUpCommands.TryGetValue(pair.Key, out command))
                            {
                                command.Execute();
                            }
                        }
                    }
                }
            }

            GamePadState gamePad = this.main.GamePadState;

            if (gamePad.IsConnected)
            {
                if (this.nextInputListeners.Count > 0 || this.AnyInputDown.Bindings.Count > 0)
                {
                    GamePadState   lastGamePad = this.main.LastGamePadState;
                    List <Buttons> buttons     = new List <Buttons>();
                    if (gamePad.IsButtonDown(Buttons.A) && !lastGamePad.IsButtonDown(Buttons.A))
                    {
                        buttons.Add(Buttons.A);
                    }
                    if (gamePad.IsButtonDown(Buttons.B) && !lastGamePad.IsButtonDown(Buttons.B))
                    {
                        buttons.Add(Buttons.B);
                    }
                    if (gamePad.IsButtonDown(Buttons.Back) && !lastGamePad.IsButtonDown(Buttons.Back))
                    {
                        buttons.Add(Buttons.Back);
                    }
                    if (gamePad.IsButtonDown(Buttons.DPadDown) && !lastGamePad.IsButtonDown(Buttons.DPadDown))
                    {
                        buttons.Add(Buttons.DPadDown);
                    }
                    if (gamePad.IsButtonDown(Buttons.DPadLeft) && !lastGamePad.IsButtonDown(Buttons.DPadLeft))
                    {
                        buttons.Add(Buttons.DPadLeft);
                    }
                    if (gamePad.IsButtonDown(Buttons.DPadRight) && !lastGamePad.IsButtonDown(Buttons.DPadRight))
                    {
                        buttons.Add(Buttons.DPadRight);
                    }
                    if (gamePad.IsButtonDown(Buttons.DPadUp) && !lastGamePad.IsButtonDown(Buttons.DPadUp))
                    {
                        buttons.Add(Buttons.DPadUp);
                    }
                    if (gamePad.IsButtonDown(Buttons.LeftShoulder) && !lastGamePad.IsButtonDown(Buttons.LeftShoulder))
                    {
                        buttons.Add(Buttons.LeftShoulder);
                    }
                    if (gamePad.IsButtonDown(Buttons.RightShoulder) && !lastGamePad.IsButtonDown(Buttons.RightShoulder))
                    {
                        buttons.Add(Buttons.RightShoulder);
                    }
                    if (gamePad.IsButtonDown(Buttons.LeftStick) && !lastGamePad.IsButtonDown(Buttons.LeftStick))
                    {
                        buttons.Add(Buttons.LeftStick);
                    }
                    if (gamePad.IsButtonDown(Buttons.RightStick) && !lastGamePad.IsButtonDown(Buttons.RightStick))
                    {
                        buttons.Add(Buttons.RightStick);
                    }
                    if (gamePad.IsButtonDown(Buttons.LeftThumbstickDown) && !lastGamePad.IsButtonDown(Buttons.LeftThumbstickDown))
                    {
                        buttons.Add(Buttons.LeftThumbstickDown);
                    }
                    if (gamePad.IsButtonDown(Buttons.LeftThumbstickRight) && !lastGamePad.IsButtonDown(Buttons.LeftThumbstickRight))
                    {
                        buttons.Add(Buttons.LeftThumbstickRight);
                    }
                    if (gamePad.IsButtonDown(Buttons.LeftThumbstickLeft) && !lastGamePad.IsButtonDown(Buttons.LeftThumbstickLeft))
                    {
                        buttons.Add(Buttons.LeftThumbstickLeft);
                    }
                    if (gamePad.IsButtonDown(Buttons.LeftThumbstickUp) && !lastGamePad.IsButtonDown(Buttons.LeftThumbstickUp))
                    {
                        buttons.Add(Buttons.LeftThumbstickUp);
                    }
                    if (gamePad.IsButtonDown(Buttons.RightThumbstickDown) && !lastGamePad.IsButtonDown(Buttons.RightThumbstickDown))
                    {
                        buttons.Add(Buttons.RightThumbstickDown);
                    }
                    if (gamePad.IsButtonDown(Buttons.RightThumbstickRight) && !lastGamePad.IsButtonDown(Buttons.RightThumbstickRight))
                    {
                        buttons.Add(Buttons.RightThumbstickRight);
                    }
                    if (gamePad.IsButtonDown(Buttons.RightThumbstickLeft) && !lastGamePad.IsButtonDown(Buttons.RightThumbstickLeft))
                    {
                        buttons.Add(Buttons.RightThumbstickLeft);
                    }
                    if (gamePad.IsButtonDown(Buttons.RightThumbstickUp) && !lastGamePad.IsButtonDown(Buttons.RightThumbstickUp))
                    {
                        buttons.Add(Buttons.RightThumbstickUp);
                    }
                    if (gamePad.IsButtonDown(Buttons.LeftTrigger) && !lastGamePad.IsButtonDown(Buttons.LeftTrigger))
                    {
                        buttons.Add(Buttons.LeftTrigger);
                    }
                    if (gamePad.IsButtonDown(Buttons.RightTrigger) && !lastGamePad.IsButtonDown(Buttons.RightTrigger))
                    {
                        buttons.Add(Buttons.RightTrigger);
                    }
                    if (gamePad.IsButtonDown(Buttons.X) && !lastGamePad.IsButtonDown(Buttons.X))
                    {
                        buttons.Add(Buttons.X);
                    }
                    if (gamePad.IsButtonDown(Buttons.Y) && !lastGamePad.IsButtonDown(Buttons.Y))
                    {
                        buttons.Add(Buttons.Y);
                    }
                    if (gamePad.IsButtonDown(Buttons.Start) && !lastGamePad.IsButtonDown(Buttons.Start))
                    {
                        buttons.Add(Buttons.Start);
                    }

                    if (buttons.Count > 0)
                    {
                        if (this.AnyInputDown.Bindings.Count > 0)
                        {
                            for (int i = 0; i < buttons.Count; i++)
                            {
                                this.AnyInputDown.Execute(new PCInputBinding {
                                    GamePadButton = buttons[i]
                                });
                            }
                        }
                        if (this.nextInputListeners.Count > 0)
                        {
                            this.notifyNextInputListeners(new PCInputBinding {
                                GamePadButton = buttons[0]
                            });
                        }
                    }
                }

                foreach (KeyValuePair <Buttons, Property <bool> > pair in this.buttonProperties)
                {
                    bool newValue = gamePad.IsButtonDown(pair.Key);
                    if (newValue != pair.Value.Value)
                    {
                        pair.Value.Value = newValue;
                        if (!this.preventKeyDownEvents)
                        {
                            if (newValue)
                            {
                                Command command;
                                if (buttonDownCommands.TryGetValue(pair.Key, out command))
                                {
                                    command.Execute();
                                }
                            }
                            else
                            {
                                Command command;
                                if (buttonUpCommands.TryGetValue(pair.Key, out command))
                                {
                                    command.Execute();
                                }
                            }
                        }
                    }
                }
            }

            foreach (KeyValuePair <Keys, Property <bool> > pair in this.keyProperties)
            {
                bool newValue = keyboard.IsKeyDown(pair.Key);
                if (newValue != pair.Value.Value)
                {
                    pair.Value.Value = newValue;
                    if (!this.preventKeyDownEvents)
                    {
                        if (newValue)
                        {
                            Command command;
                            if (this.keyDownCommands.TryGetValue(pair.Key, out command))
                            {
                                command.Execute();
                            }
                        }
                        else
                        {
                            Command command;
                            if (keyUpCommands.TryGetValue(pair.Key, out command))
                            {
                                command.Execute();
                            }
                        }
                    }
                }
            }

            if (!this.chordActivated && !this.preventKeyDownEvents)
            {
                if (keys.Length == 2)
                {
                    Chord chord = new Chord();
                    if (keys[1] == Keys.LeftAlt || keys[1] == Keys.LeftControl || keys[1] == Keys.LeftShift || keys[1] == Keys.LeftWindows ||
                        keys[1] == Keys.RightAlt || keys[1] == Keys.RightControl || keys[1] == Keys.RightShift || keys[1] == Keys.RightWindows)
                    {
                        chord.Modifier = keys[1];
                        chord.Key      = keys[0];
                    }
                    else
                    {
                        chord.Modifier = keys[0];
                        chord.Key      = keys[1];
                    }

                    Command chordCommand;
                    if (this.chords.TryGetValue(chord, out chordCommand))
                    {
                        chordCommand.Execute();
                        this.chordActivated = true;
                    }
                }
            }
            else if (keyboard.GetPressedKeys().Length == 0)
            {
                this.chordActivated = false;
            }

            if (this.EnableMouse)
            {
                MouseState mouse = this.main.MouseState;
                this.handleMouse();

                bool newLeftMouseButton = mouse.LeftButton == ButtonState.Pressed;
                if (newLeftMouseButton != this.LeftMouseButton)
                {
                    this.LeftMouseButton.Value = newLeftMouseButton;
                    if (!this.preventKeyDownEvents)
                    {
                        if (newLeftMouseButton)
                        {
                            if (!this.temporarilyIgnoreLMB)
                            {
                                if (this.nextInputListeners.Count > 0)
                                {
                                    this.notifyNextInputListeners(new PCInputBinding {
                                        MouseButton = MouseButton.LeftMouseButton
                                    });
                                }
                                this.LeftMouseButtonDown.Execute();
                                this.AnyInputDown.Execute(new PCInputBinding {
                                    MouseButton = MouseButton.LeftMouseButton
                                });
                            }
                        }
                        else
                        {
                            if (this.temporarilyIgnoreLMB)
                            {
                                this.temporarilyIgnoreLMB = false;
                            }
                            else
                            {
                                this.LeftMouseButtonUp.Execute();
                            }
                        }
                    }
                }

                bool newMiddleMouseButton = mouse.MiddleButton == ButtonState.Pressed;
                if (newMiddleMouseButton != this.MiddleMouseButton)
                {
                    this.MiddleMouseButton.Value = newMiddleMouseButton;
                    if (!this.preventKeyDownEvents)
                    {
                        if (newMiddleMouseButton)
                        {
                            if (this.nextInputListeners.Count > 0)
                            {
                                this.notifyNextInputListeners(new PCInputBinding {
                                    MouseButton = MouseButton.MiddleMouseButton
                                });
                            }
                            this.MiddleMouseButtonDown.Execute();
                            this.AnyInputDown.Execute(new PCInputBinding {
                                MouseButton = MouseButton.MiddleMouseButton
                            });
                        }
                        else
                        {
                            this.MiddleMouseButtonUp.Execute();
                        }
                    }
                }

                bool newRightMouseButton = mouse.RightButton == ButtonState.Pressed;
                if (newRightMouseButton != this.RightMouseButton)
                {
                    this.RightMouseButton.Value = newRightMouseButton;
                    if (!this.preventKeyDownEvents)
                    {
                        if (newRightMouseButton)
                        {
                            if (this.nextInputListeners.Count > 0)
                            {
                                this.notifyNextInputListeners(new PCInputBinding {
                                    MouseButton = MouseButton.RightMouseButton
                                });
                            }
                            this.RightMouseButtonDown.Execute();
                            this.AnyInputDown.Execute(new PCInputBinding {
                                MouseButton = MouseButton.RightMouseButton
                            });
                        }
                        else
                        {
                            this.RightMouseButtonUp.Execute();
                        }
                    }
                }

                int newScrollWheel = mouse.ScrollWheelValue;
                int oldScrollWheel = this.ScrollWheel;
                if (newScrollWheel != oldScrollWheel)
                {
                    this.ScrollWheel.Value = newScrollWheel;
                    if (!this.preventKeyDownEvents)
                    {
                        this.MouseScrolled.Execute(newScrollWheel > oldScrollWheel ? 1 : -1);
                    }
                }
            }
            this.preventKeyDownEvents = false;
        }
Exemple #52
0
        public void getRootNoteTestBang()
        {
            Chord c = new Chord("C#");

            Assert.AreEqual("C#", c.getRootNote());
        }
Exemple #53
0
        public void poll()
        {
            OscBundle bundle = null;

            while (bundle == null)
            {
                bundle = (OscBundle)listener.Receive();
                Thread.Sleep(1);
            }

            //Debug.Log("Received a bundle!");
            List <OscMessage> messages = bundle.Messages;

            OscMessage lastMessage = bundle.Messages[bundle.Messages.Count - 1];

            switch (lastMessage.Address)
            {
            case "/notes_receiver":
                Note   note       = new Note();
                object midiNumber = lastMessage.Arguments[0];
                object start      = lastMessage.Arguments[1];
                object duration   = lastMessage.Arguments[2];
                // Typecheck to make sure that message is intact
                if (midiNumber is int midiNumberInt)
                {
                    note.MidiNumber = midiNumberInt;
                    note.Start      = (float)start;
                    note.Duration   = (float)duration;
                    note.Starts.Add((float)start);
                    note.Durations.Add((float)duration);

                    individualNote = note;
                    receivedNote   = true;
                }
                break;

            case "/notes_complete":
                isDoneReceivingNotes = true;
                break;

            case "/chords_receiver":
                int    i          = 0;
                object commonName = lastMessage.Arguments[i];
                // Typecheck to make sure that message is intact
                if (commonName is string commonNameString)
                {
                    // Initialise chord object
                    chord            = new Chord();
                    chord.CommonName = commonNameString;
                    // Add all subsequent ints (notes) to the chord object until separator "|" is hit
                    object next = lastMessage.Arguments[++i];
                    while (next is int nextMidiNumberInt)
                    {
                        Note individualNote = new Note(nextMidiNumberInt);
                        chord.AddNote(individualNote);
                        next = lastMessage.Arguments[++i];
                    }
                    // After notes (int) in OSC message it's beat and duration (floats)
                    var chordStart = (float)next;
                    next = lastMessage.Arguments[++i];
                    var chordDuration = (float)next;

                    chord.Start    = chordStart;
                    chord.Duration = chordDuration;
                    receivedChord  = true;
                }
                break;
            }
            poll();
        }
Exemple #54
0
 public void getSixthStringTwelfthFret()
 {
     Assert.AreEqual("E", Chord.GetNoteLetter(5, 12));
 }
Exemple #55
0
        public void PlayChord(Chord c)
        {
            state = 0;
            //midiOut.Send(MidiMessage.ChangePatch((int)PatchNames.Electric_Piano_2, 1).RawData);
            foreach (Note n in c.Notes)
            {
                midiOut.Send(MidiMessage.StartNote(n.Pitch, c.Velocity, 1).RawData);
            }

            Thread.Sleep((int)(Note.ToRealDuration(c.Duration) * 1000));
            foreach (Note n in c.Notes)
            {
                midiOut.Send(MidiMessage.StopNote(n.Pitch, 0, 1).RawData);
            }
        }
Exemple #56
0
 public void getFifthStringFirstFret()
 {
     Assert.AreEqual("B", Chord.GetNoteLetter(4, 0));
 }
Exemple #57
0
        private void WriteBeat(Chord chord, int trackNumber, int numStrings, bool changeTempo, int newTempo)
        {
            const Byte DOTTED_NOTE = 1;
            const Byte CHORD_DIAGRAM = (1 << 1);
            const Byte TEXT = (1 << 2);
            const Byte BEAT_EFFECTS = (1 << 3);
            const Byte MIX_TABLE = (1 << 4);
            const Byte TUPLET = (1 << 5);
            const Byte REST = (1 << 6);
            const short STRING_EFFECTS = (1 << 5);
            const Byte TAPPING = 1;
            const Byte SLAPPING = 2;
            const Byte POPPING = 3;

            // figure out beat duration
            bool dotted = false;
            bool triplet = false;
            SByte duration = 0;

            switch (chord.Duration)
            {
                case 192:
                    duration = -2;
                    break;
                case 144:
                    duration = -1;
                    dotted = true;
                    break;
                case 96:
                    duration = -1;
                    break;
                case 72:
                    duration = 0;
                    dotted = true;
                    break;
                case 48:
                    duration = 0;
                    break;
                case 36:
                    duration = 1;
                    dotted = true;
                    break;
                case 32:
                    duration = 0;
                    triplet = true;
                    break;
                case 24:
                    duration = 1;
                    break;
                case 18:
                    duration = 2;
                    dotted = true;
                    break;
                case 16:
                    duration = 1;
                    triplet = true;
                    break;
                case 12:
                    duration = 2;
                    break;
                case 9:
                    duration = 3;
                    dotted = true;
                    break;
                case 8:
                    duration = 2;
                    triplet = true;
                    break;
                case 6:
                    duration = 3;
                    break;
                case 4:
                    duration = 3;
                    triplet = true;
                    break;
                case 3:
                    duration = 4;
                    break;
                case 2:
                    duration = 4;
                    triplet = true;
                    break;
                default:
                    Console.WriteLine("  Warning: Rhythm Duration {0} not handled, defaulting to quarter note.", chord.Duration);
                    duration = 0;
                    break;
            }

            Byte flags = 0;
            if (chord.Notes.Count == 0)
                flags |= REST;
            if (dotted)
                flags |= DOTTED_NOTE;
            if (triplet)
                flags |= TUPLET;
            if (changeTempo)
                flags |= MIX_TABLE;
            if (chord.Section != null)
                flags |= TEXT;
            bool tapped = false;
            foreach (var kvp in chord.Notes)
            {
                if (kvp.Value.Tapped)
                    tapped = true;
            }
            if (chord.Popped || chord.Slapped || tapped)
                flags |= BEAT_EFFECTS;

            var chordTemplates = score.Tracks[trackNumber].ChordTemplates;
            if (chord.ChordId != -1 && chord.ChordId != prevChordId[trackNumber] &&
                chordTemplates.ContainsKey(chord.ChordId) &&
                chordTemplates[chord.ChordId].Name != string.Empty)
            {
                flags |= CHORD_DIAGRAM;
            }
            prevChordId[trackNumber] = chord.ChordId;

            writer.Write(flags);
            if (chord.Notes.Count == 0)
                writer.Write((Byte)2);  // 2 is an actual rest, 0 is silent
            writer.Write(duration);
            if (triplet)
                writer.Write((Int32)3);  // declare a triplet beat

            // chord diagram
            if ((flags & CHORD_DIAGRAM) != 0)
            {
                var chordTemplate = chordTemplates[chord.ChordId];
                WriteChordTemplate(chordTemplate);
            }
            // section names
            if ((flags & TEXT) != 0)
                WriteDoublePrefixedString(chord.Section);

            // beat effects
            if ((flags & BEAT_EFFECTS) != 0)
            {
                short effectsFlag = 0;
                if (chord.Popped || chord.Slapped || tapped)
                    effectsFlag |= STRING_EFFECTS;
                writer.Write(effectsFlag);
                if (tapped)
                    writer.Write(TAPPING);
                else if (chord.Slapped)
                    writer.Write(SLAPPING);
                else if (chord.Popped)
                    writer.Write(POPPING);
            }

            // mix table (used for changing tempo)
            if ((flags & MIX_TABLE) != 0)
            {
                for (int i = 0; i < 23; ++i)
                    writer.Write((Byte)0xff);
                WriteDoublePrefixedString("");  // tempo string
                writer.Write((Int32)newTempo);
                writer.Write((Byte)0);  // means new tempo takes effect immediately
                writer.Write((Byte)1);
                writer.Write((Byte)0xff);
            }

            // now write the actual notes. a flag indicates which strings are being played
            Byte stringFlags = 0;
            int stringOffset = 7 - numStrings;
            foreach (var kvp in chord.Notes)
                stringFlags |= (Byte)(1 << (kvp.Key+stringOffset));
            writer.Write(stringFlags);
            var notes = chord.Notes.Values.OrderByDescending(x => x.String);
            foreach (var note in notes)
            {
                WriteNote(note, trackNumber);
            }
            // there seem to be a few accidental ties set in the Rocksmith XMLs
            // so unset the tie status on any strings that weren't in the current chord.
            for (int i = 0; i < 6; ++i)
            {
                if (!chord.Notes.ContainsKey(i))
                    tieNotes[trackNumber][i] = false;
            }

            short noteTranspose = 0;
            writer.Write(noteTranspose);
        }
Exemple #58
0
 public void getFifthStringTwelfthFret()
 {
     Assert.AreEqual("B", Chord.GetNoteLetter(4, 12));
 }
Exemple #59
0
        static void ChordTest2()
        {
            MusicPlayer player = new MusicPlayer();
            //player.SetPatch((int)PatchNames.Overdriven_Guitar, 1);
            var a = new Chord(new NoteNames[] { NoteNames.C, NoteNames.E, NoteNames.G }, 4, Durations.hn);
            var b = new Chord(new NoteNames[] { NoteNames.Cs, NoteNames.E, NoteNames.GS }, 4, Durations.hn);
            var c = new Chord(new NoteNames[] { NoteNames.D, NoteNames.F, NoteNames.A }, 4, Durations.hn);
            var d = new Chord(new NoteNames[] { NoteNames.E, NoteNames.G, NoteNames.B }, 4, Durations.hn);
            var e = new Chord(new NoteNames[] { NoteNames.F, NoteNames.A, NoteNames.C }, 4, Durations.hn);
            var f = new Chord(new NoteNames[] { NoteNames.G, NoteNames.B, NoteNames.D }, 4, Durations.hn);
            var g = new Chord(new NoteNames[] { NoteNames.A, NoteNames.C, NoteNames.E }, 4, Durations.hn);
            var h = new Chord(new NoteNames[] { NoteNames.B, NoteNames.D, NoteNames.F }, 4, Durations.hn);
            var k = new Chord[] { a, b, c, d, e, f, g, h };
            Random r = new Random();
            while (true)
            {
                var chord = k[r.Next(0, k.Length)];
                chord.Duration = (int)((Durations)Math.Pow(2, r.Next(2, 6)));
                player.PlayChord(chord);

            }
        }
Exemple #60
0
 public void getFourthStringFirstFret()
 {
     Assert.AreEqual("G", Chord.GetNoteLetter(3, 0));
 }