Ejemplo n.º 1
0
        private void DisplayScaleCore(Scale targetScale)
        {
            try
            {
                var noteInScale = targetScale.GetElementsNote().ToList();

                foreach (var children in Pianokey.Children)
                {
                    Image  img  = children as Image;
                    string tag  = img.Tag as string;
                    Note   note = NoteUtils.ParseNote(tag.Split('-')[1]);
                    if (noteInScale.Contains(note))
                    {
                        ChangePianoKeyChooseStatus(img, status: "Choose");
                    }
                    else
                    {
                        ChangePianoKeyChooseStatus(img, status: "CancelChoose");
                    }
                }
            }
            catch (Exception)
            {
                MessageBox.Show("音阶键位显示出现未知错误!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
        }
Ejemplo n.º 2
0
        private void DisplayScaleClickEvent(object sender, RoutedEventArgs e)
        {
            ClearChoosePianoKey();
            string keyStr = ScaleKey.Text;
            string type   = ScaleType.Text;

            ChordNameTextBox.Text = string.Empty;

            Scale targetScale = new Scale(NoteUtils.ParseNote(keyStr), Common.TryEnum <Tonic>(type));

            DisplayScaleCore(targetScale);
        }
Ejemplo n.º 3
0
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            Left.Visibility  = Visibility.Hidden;
            Right.Visibility = Visibility.Hidden;
            if (PianoKeyChooseNote.Count() == 0)
            {
                MessageBox.Show("未指定钢琴上的键位!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
            }
            else
            {
                ArrowMode = "DetectChord";
                string style       = PianoChordStyle.Text;
                string bassStyle   = PianoChordBassStyle.Text;
                string bassNoteStr = PianoKeyChooseNote.First(s =>
                                                              int.Parse(s.Split('-')[2]) == PianoKeyChooseNote.Min(k => int.Parse(k.Split('-')[2]))).Split('-')[1];
                List <Note> NoteList = new List <Note>();

                foreach (var keyNote in PianoKeyChooseNote)
                {
                    int    index   = int.Parse(keyNote.Split('-')[0]);
                    string noteStr = keyNote.Split('-')[1];
                    var    note    = NoteUtils.ParseNote(noteStr);
                    if (!NoteList.Contains(note))
                    {
                        NoteList.Add(note);
                    }
                }

                RetroChord res;
                try
                {
                    if (bassStyle == "不指定低音")
                    {
                        res = ChordAnalysis.ChordRecognizer(NoteList);
                    }
                    else
                    {
                        res = ChordAnalysis.ChordRecognizer(NoteList, bass: NoteUtils.ParseNote(bassNoteStr));
                    }


                    candidate             = res.Select(r => r.chord).ToList();
                    ChordNameTextBox.Text = res.BestChord.Title;
                    Left.Visibility       = Visibility.Visible;
                    Right.Visibility      = Visibility.Visible;
                }
                catch
                {
                    MessageBox.Show("和弦分析出现未知错误!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Call from JQuery to find the chords.
        /// </summary>
        /// <param name="instrument">The instrument.</param>
        /// <param name="tuning">The tuning.</param>
        /// <param name="notes">The root note for the chord.</param>
        /// <param name="chordQualities">The chord qualities.</param>
        /// <param name="numFrets">The number of frets to display.</param>
        /// <param name="maxFrets">The maximum number of frets to use.</param>
        /// <param name="maxReach">The maximum fret reach for the fingers.</param>
        /// <param name="autoAddBarres">Auto add barres?</param>
        /// <param name="allowOpenStrings">Allow open strings?</param>
        /// <param name="allowMutedStrings">Allow muted strings?</param>
        /// <param name="mirrorResults">Mirror the results for left-handed chords?</param>
        /// <param name="allowRootlessChords">Allow rootless chords?</param>
        /// <returns>List of SVG images to display in the UI.</returns>
        public JsonResult FindChords(string instrument, string tuning, string notes, string chordQualities, string numFrets, string maxFrets, string maxReach, string autoAddBarres, string allowOpenStrings, string allowMutedStrings, string mirrorResults, string allowRootlessChords)
        {
            // Initialize the ConfigFile object.
            InitConfig();

            // Define the objects.
            Instrument         Instrument     = null;
            ChordQuality       ChordQuality   = null;
            ChordFinderOptions myOptions      = null;
            ChordFinder        chordFinder    = null;
            ChordResultSet     chordResultSet = null;
            ChordOptions       chordOptions   = null;
            Tuning             Tuning         = null;
            Note myNote = NoteUtils.ParseNote(notes);

            Instrument   = GetAnInstrument(instrument);
            ChordQuality = GetChordQuality(chordQualities);

            if (Instrument != null)
            {
                // Instantiate the selected tuning object from the instrument.
                Tuning = GetTheTuning(Instrument, tuning);

                // Instantiate the chord finder options.
                myOptions = BuildChordFinderOptions(instrument, tuning, numFrets, maxFrets, maxReach, autoAddBarres, allowOpenStrings, allowMutedStrings, mirrorResults, allowRootlessChords);

                // Instantiate the chord finder object.
                chordFinder = new ChordFinder(Instrument, Tuning);

                // Instantiate the chord result set.
                chordResultSet = chordFinder.FindChords(myNote, ChordQuality, myOptions);

                // Instantiate the chord options.
                chordOptions = BuildChordOptions();

                // Build the list of SVG images to return to the screen.
                return(Json(BuildSVGList(chordResultSet, chordOptions), JsonRequestBehavior.AllowGet));
            }
            else
            {
                // The instrument doesn't exist.
                return(Json(String.Empty, JsonRequestBehavior.AllowGet));
            }
        }
Ejemplo n.º 5
0
 private void DisplayKeyCore(string tag)
 {
     try
     {
         foreach (var children in Pianokey.Children)
         {
             Image  img    = children as Image;
             string imgTag = img.Tag as string;
             Note   note   = NoteUtils.ParseNote(imgTag.Split('-')[1]);
             if (imgTag == tag)
             {
                 ChangePianoKeyChooseStatus(img, status: "Choose");
                 break;
             }
         }
     }
     catch (Exception)
     {
         MessageBox.Show("和弦显示出现未知错误!", "Error", MessageBoxButton.OK, MessageBoxImage.Error);
     }
 }
Ejemplo n.º 6
0
        public static FullNote Parse(string s)
        {
            if (StringUtils.IsNullOrWhiteSpace(s))
            {
                throw new ArgumentNullException(nameof(s));
            }

            s = s.Trim();

            int splitIndex = s.IndexOfAny(digits);

            if (splitIndex <= 0)
            {
                throw new ArgumentException(Strings.InvalidNoteArgumentExceptionMessage);
            }

            string notePortion   = s.Substring(0, splitIndex);
            string octavePortion = s.Substring(splitIndex);

            Note note   = NoteUtils.ParseNote(notePortion);
            int  octave = int.Parse(octavePortion);

            return(new FullNote(note, octave));
        }