/// <summary>
        /// Creates a representation for a natural.
        /// </summary>
        /// <param name="naturalNote">Can't be an accidental.</param>
        internal NoteRepresentation(Note naturalNote)
        {
            if (naturalNote.IsAccidental())
                throw new Exception("Only a natural can be passed to this constructor.");

            Note = naturalNote;
            Name = GetNaturalNoteName(naturalNote);
            Accidental = AccidentalType.Natural;
        }
        /// <summary>
        /// Creates a new StaffFlashcardGenerator.
        /// </summary>
        /// <param name="staffs">This flags value indicates which staffs to include.</param>
        public StaffFlashcardGenerator(StaffFlashcardGeneratorArgs args)
        {
            if (args.Staffs == 0)
                throw new ArgumentException("Need at least one Staff to construct a staff flashcard generator.");
            if (args.Accidentals == 0)
                throw new ArgumentException("Need at least one accidental type to construct a staff flashcard generator.");

            Staffs = args.Staffs;
            Accidentals = args.Accidentals;
        }
Пример #3
0
        /// <summary>
        /// Calculates the accidental for the given note and assignes the value to it.
        /// The new accidental type is also registered within the current scope
        /// </summary>
        /// <param name="note"></param>
        /// <param name="noteLine"></param>
        /// <returns></returns>
        public AccidentalType ApplyAccidental(Note note)
        {
            var noteValue = note.RealValue;
            var ks        = note.Beat.Voice.Bar.MasterBar.KeySignature;
            var ksi       = (ks + 7);
            var index     = (noteValue % 12);
            //var octave = (noteValue / 12);

            AccidentalType accidentalToSet = AccidentalNotes[ksi][index];

            // calculate the line where the note will be according to the accidental
            int noteLine = GetNoteLineWithAccidental(note, accidentalToSet);

            // TODO: change accidentalToSet according to note.AccidentalMode

            // if there is already an accidental registered, we check if we
            // have a new accidental
            var updateAccidental = true;

            if (note.Beat.Voice.Bar.Track.IsPercussion)
            {
                accidentalToSet = AccidentalType.None;
            }
            else if (_registeredAccidentals.ContainsKey(noteLine))
            {
                var registeredAccidental = _registeredAccidentals[noteLine];

                // we only need to do anything if we are changing the accidental
                if (registeredAccidental == accidentalToSet)
                {
                    // we set the accidental to none, as the accidental is already set by a previous note
                    accidentalToSet  = AccidentalType.None;
                    updateAccidental = false;
                }
                // check if we need naturalizing
                else if (accidentalToSet == AccidentalType.None)
                {
                    accidentalToSet = AccidentalType.Natural;
                }
            }

            if (updateAccidental)
            {
                if ((accidentalToSet == AccidentalType.None || accidentalToSet == AccidentalType.Natural))
                {
                    _registeredAccidentals.Remove(noteLine);
                }
                else
                {
                    _registeredAccidentals[noteLine] = accidentalToSet;
                }
            }

            return(accidentalToSet);
        }
Пример #4
0
        private int GetNoteLineWithAccidental(Note n, AccidentalType accidentalToSet)
        {
            var value = n.Beat.Voice.Bar.Track.IsPercussion ? PercussionMapper.MapNoteForDisplay(n) : n.RealValue;
            var ks    = n.Beat.Voice.Bar.MasterBar.KeySignature;
            var clef  = n.Beat.Voice.Bar.Clef;

            var index  = value % 12;
            var octave = (value / 12);

            // Initial Position
            var steps = OctaveSteps[(int)clef];

            // Move to Octave
            steps -= (octave * StepsPerOctave);

            // get the step list for the current keySignature
            var stepList = ModelUtils.KeySignatureIsSharp(ks) || ModelUtils.KeySignatureIsNatural(ks)
                ? SharpNoteSteps
                : FlatNoteSteps;

            //Add offset for note itself
            int offset = 0;

            switch (n.AccidentalMode)
            {
            // TODO: provide line according to accidentalMode
            case NoteAccidentalMode.Default:
            case NoteAccidentalMode.SwapAccidentals:
            case NoteAccidentalMode.ForceNatural:
            case NoteAccidentalMode.ForceFlat:
            case NoteAccidentalMode.ForceSharp:
            default:
                // normal behavior: simply use the position where
                // the keysignature defines the position
                offset = stepList[index];
                break;
            }
            steps -= stepList[index];

            // TODO: It seems note heads are always one step above the calculated line
            // maybe the SVG paths are wrong, need to recheck where step=0 is really placed
            var line = steps + NoteStepCorrection;

            _appliedScoreLines[GetNoteId(n)] = line;
            return(line);
        }
Пример #5
0
        private static MusicFontSymbol GetMusicSymbol(AccidentalType accidentalType)
        {
            switch (accidentalType)
            {
            case AccidentalType.Natural:
                return(MusicFontSymbol.AccidentalNatural);

            case AccidentalType.Sharp:
                return(MusicFontSymbol.AccidentalSharp);

            case AccidentalType.Flat:
                return(MusicFontSymbol.AccidentalFlat);

            case AccidentalType.NaturalQuarterNoteUp:
                return(MusicFontSymbol.AccidentalQuarterToneNaturalArrowUp);

            case AccidentalType.SharpQuarterNoteUp:
                return(MusicFontSymbol.AccidentalQuarterToneSharpArrowUp);

            case AccidentalType.FlatQuarterNoteUp:
                return(MusicFontSymbol.AccidentalQuarterToneFlatArrowUp);
            }
            return(MusicFontSymbol.None);
        }
 /// <summary>
 /// Creates a new note representation.
 /// </summary>
 internal NoteRepresentation(Note note, AccidentalType accidental, NoteName name)
 {
     Note = note;
     Accidental = accidental;
     Name = name;
 }
Пример #7
0
        private int GetNoteLineWithAccidental(Note n, AccidentalType accidentalToSet)
        {
            var value = n.Beat.Voice.Bar.Track.IsPercussion ? PercussionMapper.MapValue(n) : n.RealValue;
            var ks = n.Beat.Voice.Bar.MasterBar.KeySignature;
            var clef = n.Beat.Voice.Bar.Clef;

            var index = value % 12;
            var octave = (value / 12);

            // Initial Position
            var steps = OctaveSteps[(int)clef];

            // Move to Octave
            steps -= (octave * StepsPerOctave);

            // get the step list for the current keySignature
            var stepList = ModelUtils.KeySignatureIsSharp(ks) || ModelUtils.KeySignatureIsNatural(ks)
                ? SharpNoteSteps
                : FlatNoteSteps;

            //Add offset for note itself
            int offset = 0;
            switch (n.AccidentalMode)
            {
                // TODO: provide line according to accidentalMode
                case NoteAccidentalMode.Default:
                case NoteAccidentalMode.SwapAccidentals:
                case NoteAccidentalMode.ForceNatural:
                case NoteAccidentalMode.ForceFlat:
                case NoteAccidentalMode.ForceSharp:
                default:
                    // normal behavior: simply use the position where
                    // the keysignature defines the position
                    offset = stepList[index];
                    break;
            }
            steps -= stepList[index];

            // TODO: It seems note heads are always one step above the calculated line
            // maybe the SVG paths are wrong, need to recheck where step=0 is really placed
            var line = steps + NoteStepCorrection;
            _appliedScoreLines[GetNoteId(n)] = line;
            return line;
        }
Пример #8
0
 public AccidentalGlyph(float x, float y, AccidentalType accidentalType, bool isGrace = false)
     : base(x, y, isGrace ? NoteHeadGlyph.GraceScale : 1, GetMusicSymbol(accidentalType))
 {
     _isGrace = isGrace;
 }