示例#1
0
        /// <summary>
        /// Updates fret note's from the NoteList.
        /// Updates their state and hightlight properties.
        /// Shifts their tunings.
        /// </summary>
        /// <param name="newTuning">Passes its value to Tuning property</param>
        public void UpdateTuning(string newTuning)
        {
            Tuning = newTuning;

            string[] scale = (from node in Doc.Descendants("Scales").Elements("Scale")
                              where node.Element("Name").Value == Scale
                              select node.Element("Interval").Value).Single().Split(' ');
            string[] tuning = (from node in Doc.Descendants("Tunings").Elements("Tuning")
                               where node.Element("Name").Value == Tuning && node.Attribute("strings").Value == Strings.ToString()
                               select node.Element("Interval").Value).Single().Split(' ');

            for (int numString = 0; numString < NoteList.Count; numString++)
            {
                int index = int.Parse(tuning[numString]);     // Getting individual string tunning

                for (int numFret = 0; numFret < NoteList[numString].Count; numFret++)
                {
                    // Calculating note order based on tuning and root note
                    IntLimited key = new IntLimited(numFret, 0, 12);
                    key.Value = key + index;

                    // Shifting the note
                    NoteList[numString][numFret].ShiftTuning(key.Value);

                    // Checking if note fits scale
                    NoteList[numString][numFret].ChangeState(scale.Contains(new IntLimited(key.Value - Root, 0, 12).Value.ToString()) ? true : false);

                    // Highlighting the root
                    NoteList[numString][numFret].HighlightRoot(Root);
                }
            }
        }
示例#2
0
        /// <summary>
        /// Sets the tooltip based on the Index and Root properties values.
        /// </summary>
        private void SetToolTip()
        {
            IntLimited interval = new IntLimited(Index - Root, 0, 12);

            noteBody.ToolTip = (from node in XDocument.Load(System.IO.Directory.GetCurrentDirectory() + @"\Data\Data.xml")
                                .Descendants("Ratios").Elements("Ratio")
                                where node.Attribute("id").Value == interval.Value.ToString()
                                select new StringBuilder(node.Element("Value").Value)
                                .Append(" ")
                                .Append(node.Element("Name").Value)
                                .ToString()).Single();
        }
        /// <summary>
        ///
        /// </summary>
        private void MenuMouseWheel(object sender, MouseWheelEventArgs e)
        {
            IntLimited i = new IntLimited(SelectedIndex + e.Delta / 120, 0, Items.Length);

            SelectedIndex = i.Value;
            RaiseSelectionChanged();

            SelectedItem.Content            = Items[SelectedIndex];
            Container.RenderTransformOrigin = new Point(0.5, 0.5);

            Container.RenderTransform = new RotateTransform(-SelectedIndex * 360 / Items.Length);
        }
示例#4
0
        /// <summary>
        /// Updates fret note's from the NoteList.
        /// Updates their state property.
        /// </summary>
        /// <param name="newScale">Passes its values to Scale property</param>
        public void UpdateScale(string newScale)
        {
            Scale = newScale;
            string[] scale = (from node in Doc.Descendants("Scales").Elements("Scale")
                              where node.Element("Name").Value == Scale
                              select node.Element("Interval").Value).Single().Split(' ');

            // Shifting scale to new root note
            foreach (List <FretNote> String in NoteList)
            {
                foreach (FretNote Note in String)
                {
                    IntLimited a = new IntLimited(Note.Index - Root, 0, 12);
                    Note.ChangeState(scale.Contains((a.Value).ToString()) ? true : false);
                }
            }
        }
示例#5
0
        /// <summary>
        /// Fetches tuning and scale intervals from the data file.
        /// Creates notes and fills the note list.
        /// </summary>
        private void CreateNotes()
        {
            // Passing selected tuning from database to array
            string[] tuning = (from node in Doc.Descendants("Tunings").Elements("Tuning")
                               where node.Element("Name").Value == Tuning && node.Attribute("strings").Value == Strings.ToString()
                               select node.Element("Interval").Value).Single().Split(' ');

            string[] scale = (from node in Doc.Descendants("Scales").Elements("Scale")
                              where node.Element("Name").Value == Scale
                              select node.Element("Interval").Value).Single().Split(' ');


            // Creating notes and adding them to the grid
            for (int numString = 0; numString < Strings; numString++)
            {
                List <FretNote> tempNoteList = new List <FretNote>();
                int             index        = int.Parse(tuning[numString]); // Getting individual string tunning

                for (int numFret = 0; numFret <= Frets; numFret++)
                {
                    // Calculating note order based on tuning and root note
                    IntLimited key = new IntLimited(numFret, 0, 12);
                    key.Value = key + index;

                    IntLimited a = new IntLimited(key.Value - Root, 0, 12);

                    // Checking if note fits scale
                    bool IsActive = scale.Contains(a.Value.ToString()) ? true : false;

                    // Creating the note
                    FretNote note = new FretNote(key.Value, Size * 0.8, IsActive, Root, new Point(numFret, numString), NoteGrid);
                    tempNoteList.Add(note);
                }

                NoteList.Add(tempNoteList); // Generating list of notes for future reference
            }
        }
示例#6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnSearch_Click(object sender, RoutedEventArgs e)
        {
            lbResults.Items.Clear();
            List <int> chordNotes = new List <int>();
            int        pointA     = Array.IndexOf(MusicKeys, tbOne.SelectedItem);
            Semaphore  sem        = new Semaphore(1, Environment.ProcessorCount);

            for (int row = 0; row < Menu.GetLength(1) - Active; row++)
            {
                Dispatcher.Invoke(() => {
                    sem.WaitOne();
                    string[] chord = (from node in Doc.Descendants("Chords").Elements("Chord")
                                      where node.Element("Name").Value == (string)Menu[1, row].SelectedValue
                                      select node.Element("Interval").Value).Single().Split(' ');

                    int pointB = Array.IndexOf(MusicKeys, Menu[1, row]);
                    if (pointA - pointB != 0)
                    {
                        IntLimited shiftBy = new IntLimited(pointA + pointB, 0, 12);
                    }
                    foreach (var item in chord)
                    {
                        if (!chordNotes.Contains(int.Parse(item)))
                        {
                            chordNotes.Add(int.Parse(item));
                        }
                    }
                    sem.Release();
                }, DispatcherPriority.ContextIdle);
            }

            chordNotes.Sort();

            var scales = from node in Doc.Descendants("Scales").Elements("Scale")
                         select node.Element("Interval").Value;

            List <string> found = new List <string>();

            foreach (var item in scales)
            {
                (new Thread(() => {
                    sem.WaitOne();
                    for (int note = 0; note < chordNotes.Count; note++)
                    {
                        if (item.IndexOf(note.ToString()) != -1)
                        {
                            if (note == chordNotes.Count - 1)
                            {
                                found.Add(item);
                            }
                        }
                        else
                        {
                            break;
                        }
                    }
                    sem.Release();
                })).Start();
            }

            if (found.Count > 0)
            {
                foreach (var item in found)
                {
                    lbResults.Items.Add(
                        (from node in Doc.Descendants("Scales").Elements("Scale")
                         where node.Element("Interval").Value == item
                         select node.Element("Name").Value).Single()
                        );
                }
            }
            else
            {
                lbResults.Items.Add("Unknown scale");
            }
        }