예제 #1
0
        public ChordFinderViewModel()
        {
            Options = new ChordFinderOptions(AppVM.UserConfig);
            Style   = new ChordFinderStyle(AppVM.UserConfig);

            RefreshInstruments(Options.Instrument, Options.Tuning);

            RefreshChordQualities(Options.ChordQuality);

            Results         = new ObservableCollection <ObservableDiagram>();
            SelectedResults = new ObservableCollection <ObservableDiagram>();

            SelectedResults.CollectionChanged += SelectedResults_CollectionChanged;
        }
예제 #2
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));
            }
        }
예제 #3
0
        /// <summary>
        /// Builds the chord finder options with the parameters passed in.
        /// </summary>
        /// <param name="instrument">The instrument name.</param>
        /// <param name="tuning">The tuning for the instrument.</param>
        /// <param name="numFrets">The number of frets.</param>
        /// <param name="maxFrets">The maximum number of frets.</param>
        /// <param name="maxReach">The maximum reach of 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>The chord finder object.</returns>
        private ChordFinderOptions BuildChordFinderOptions(string instrument, string tuning, string numFrets, string maxFrets, string maxReach, string autoAddBarres, string allowOpenStrings, string allowMutedStrings, string mirrorResults, string allowRootlessChords)
        {
            int  myNumFrets            = 5;
            int  myMaxFrets            = 12;
            int  myMaxReach            = 4;
            bool myAutoAddBarres       = true;
            bool myAllowOpenStrings    = true;
            bool myAllowMutedStrings   = true;
            bool myAllowRootlessChords = false;
            bool myMirrorResults       = false;

            Int32.TryParse(numFrets, out myNumFrets);
            Int32.TryParse(maxFrets, out myMaxFrets);
            Int32.TryParse(maxReach, out myMaxReach);
            bool.TryParse(autoAddBarres, out myAutoAddBarres);
            bool.TryParse(allowOpenStrings, out myAllowOpenStrings);
            bool.TryParse(allowMutedStrings, out myAllowMutedStrings);
            bool.TryParse(allowRootlessChords, out myAllowRootlessChords);
            bool.TryParse(mirrorResults, out myMirrorResults);

            ChordFinderOptions myOptions = new ChordFinderOptions(myNumFrets, myMaxFrets, myMaxReach, myAutoAddBarres, myAllowOpenStrings, myAllowMutedStrings, myAllowRootlessChords, myMirrorResults);

            return(myOptions);
        }