Exemplo n.º 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);
                }
            }
        }
Exemplo n.º 2
0
 public LangFile(string path)
 {
     Doc          = XDocument.Load(path);
     Base         = Doc.Descendants("language").First().Attribute("base")?.Value;
     Variant      = Doc.Descendants("language").First().Attribute("variant")?.Value;
     FileName     = Path.GetFileNameWithoutExtension(path);
     LangCode     = Doc.Descendants("language").First().Attribute("langcode")?.Value;
     LatestUpdate = File.GetLastWriteTimeUtc(path);
 }
Exemplo n.º 3
0
 public LangFile(string path)
 {
     Doc          = LanguageConverter.Load(path);
     Name         = Doc.Descendants("language").First().Attribute("name")?.Value;
     Base         = Doc.Descendants("language").First().Attribute("base")?.Value;
     Variant      = Doc.Descendants("language").First().Attribute("variant")?.Value;
     FilePath     = path;
     FileName     = Path.GetFileNameWithoutExtension(path);
     LatestUpdate = File.GetLastWriteTimeUtc(path);
 }
Exemplo n.º 4
0
 public LangFile(string path)
 {
     Doc          = XDocument.Load(path);
     Name         = Doc.Descendants("language").First().Attribute("name")?.Value;
     Base         = Doc.Descendants("language").First().Attribute("base")?.Value;
     Variant      = Doc.Descendants("language").First().Attribute("variant")?.Value;
     IsDefault    = Doc.Descendants("language").First().Attribute("isDefault")?.Value == "true";
     FilePath     = path;
     FileName     = Path.GetFileNameWithoutExtension(path);
     LatestUpdate = File.GetLastWriteTimeUtc(path);
 }
Exemplo n.º 5
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="scale"></param>
        private void FillScales(int scale)
        {
            // Adding scales from database
            var scales = from node in Doc.Descendants("Scales").Elements("Scale")
                         select node.Element("Name").Value;

            foreach (var item in scales)
            {
                cbScale.Items.Add(item);
            }
            cbScale.SelectedIndex = scale;
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        private void SetupSearchScale()
        {
            var chords = from node in Doc.Descendants("Chords").Elements("Chord")
                         select node.Element("Name").Value;

            Dispatcher.Invoke(() =>
            {
                foreach (var item in MusicKeys)
                {
                    tbOne.Items.Add(item);
                    tbTwo.Items.Add(item);
                    tbThree.Items.Add(item);
                }
            }, DispatcherPriority.ContextIdle);

            Dispatcher.Invoke(() =>
            {
                foreach (var item in chords)
                {
                    cbOne.Items.Add(item);
                    cbTwo.Items.Add(item);
                    cbThree.Items.Add(item);
                }
            }, DispatcherPriority.ContextIdle);

            Menu = new ComboBox[, ] {
                { tbOne, tbTwo, tbThree }, { cbOne, cbTwo, cbThree }
            };
            init = true;

            SearchScaleNoteMenu.Children.Add(new Label {
                Content = "Note 1", FontSize = 18
            });
            SearchScaleNoteMenu.Children.Add(new Viewbox {
                Child = new RadialMenu(MusicKeys, 0), Width = 180
            });
            SearchScaleNoteMenu.Children.Add(new Label {
                Content = "Note 2", FontSize = 18
            });
            SearchScaleNoteMenu.Children.Add(new Viewbox {
                Child = new RadialMenu(MusicKeys, 0), Width = 180
            });
            SearchScaleNoteMenu.Children.Add(new Label {
                Content = "Note 3", FontSize = 18
            });
            SearchScaleNoteMenu.Children.Add(new Viewbox {
                Child = new RadialMenu(MusicKeys, 0), Width = 180
            });
        }
Exemplo n.º 7
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);
                }
            }
        }
Exemplo n.º 8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="strings"></param>
        private void FillTunings(int strings)
        {
            if (cbTuning.HasItems)
            {
                cbTuning.Items.Clear();
            }

            // Adding tunings from database
            var tunings = from node in Doc.Descendants("Tunings").Elements("Tuning")
                          where node.Attribute("strings").Value == strings.ToString()
                          select node.Element("Name").Value;

            foreach (var item in tunings)
            {
                cbTuning.Items.Add(item);
            }
            cbTuning.SelectedIndex = 0;
        }
Exemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        private void FretboardApply_Click(object sender, RoutedEventArgs e)
        {
            if (SliderFrets.Value != fretboard.Frets || SliderStrings.Value != fretboard.Strings)
            {
                int oldStrings = fretboard.Strings;
                fretboard.ClearNotes();

                if (SliderStrings.Value != oldStrings)
                {
                    string t = (from node in Doc.Descendants("Tunings").Elements("Tuning")
                                where node.Attribute("strings").Value == SliderStrings.Value.ToString()
                                select node.Element("Name").Value).First();

                    fretboard = new Fretboard(mainGrid,
                                              (ushort)SliderStrings.Value,
                                              (ushort)SliderFrets.Value,
                                              4,
                                              t,
                                              cbScale.SelectedValue.ToString());

                    LabelTuning.Content = t;
                    LabelScale.Content  = cbScale.SelectedValue.ToString();

                    FillTunings((int)SliderStrings.Value); // Causes error
                }
                else
                {
                    fretboard = new Fretboard(mainGrid,
                                              (ushort)SliderStrings.Value,
                                              (ushort)SliderFrets.Value,
                                              cbRoot.SelectedIndex,
                                              (from node in Doc.Descendants("Tunings").Elements("Tuning")
                                               where node.Attribute("strings").Value == SliderStrings.Value.ToString() &&
                                               node.Element("Name").Value == cbTuning.SelectedValue.ToString()
                                               select node.Element("Name").Value).Single(),
                                              cbScale.SelectedValue.ToString());
                }
            }
        }
Exemplo n.º 10
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
            }
        }
Exemplo n.º 11
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");
            }
        }