public static KeyAccidental ConvertKeyAccidental(KeyAccidental _keyaccidobj, KeyAccid _keyaccid)
        {
            _keyaccidobj.AccidentalType = GetAccidentalType(_keyaccid);
            _keyaccidobj.PitchLocation  = GetKeyAccidPitch(_keyaccid);

            return(_keyaccidobj);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Calculates AbsolutePitch with WrittenPitch, KeyAccids and directely preceeding accidentals.
        /// </summary>
        /// <param name="_sequence">Sequence object</param>
        public static void ConvertAbsolutePitch(Sequence _sequence)
        {
            Dictionary <int, Model.AccidType> keyAccids = new Dictionary <int, AccidType>();

            Accidental lastAccid = null;

            foreach (ObjectInSequence obj in _sequence.ObjectsInSequence)
            {
                //if Accidental or KeyAccidental has AccidentalType.Null, ignore it
                if (obj is KeyAccidental testaccid)
                {
                    if (testaccid.AccidentalType == AccidType.Null)
                    {
                        continue;
                    }
                }

                if (obj.Type == ObjectType.KeyAccidental)
                {
                    KeyAccidental keyAcc = (KeyAccidental)obj;

                    if (keyAccids.ContainsKey(keyAcc.PitchLocation) == true)
                    {
                        keyAccids[keyAcc.PitchLocation] = keyAcc.AccidentalType;
                    }
                    else
                    {
                        keyAccids.Add(keyAcc.PitchLocation, keyAcc.AccidentalType);
                    }
                }
                else if (obj is Model.Custos)
                {
                    //reset key accidentals
                    keyAccids.Clear();
                }
                else if (obj.Type == ObjectType.Accidental)
                {
                    lastAccid = (Accidental)obj;
                }
                else if (obj is Model.Note note)
                {
                    int absPitch = note.WrittenPitch;

                    if (keyAccids.ContainsKey(absPitch))
                    {
                        absPitch += (int)keyAccids[absPitch];
                    }

                    //only try to change WrittenPitch if lastAccid is not null
                    if (lastAccid != null)
                    {
                        if (lastAccid.PitchLocation == note.WrittenPitch)
                        {
                            absPitch += (int)lastAccid.AccidentalType;
                        }

                        //check for bdurum to cancel bmolle signature
                        //it would be possible to check only for b/h by if (WrittenPitch % 40 == 36), but to rigid treatment would be not suitable
                        if (lastAccid.AccidentalType == AccidType.Neutral && keyAccids.ContainsKey(note.WrittenPitch))
                        {
                            if (keyAccids[note.WrittenPitch] == AccidType.Flat)
                            {
                                //apply like a sharp to cancel flat
                                absPitch += 1;
                            }
                        }

                        //resets last accidental directly after the first following note
                        lastAccid = null;
                    }

                    //handle @accid.ges
                    if (note.AccidGes != AccidType.Null)
                    {
                        absPitch += (int)note.AccidGes;
                    }

                    note.PitchWithAccid = absPitch;
                }
                else
                {
                    continue;
                }
            }
        }
Exemplo n.º 3
0
        public void BuildSequence_checkConversion()
        {
            foreach (Sequence testSequence in testList)
            {
                foreach (ObjectInSequence obj in testSequence.ObjectsInSequence)
                {
                    Assert.AreNotEqual(obj.Evidence, Evidence.Invalid);

                    switch (obj.Type)
                    {
                    case ObjectType.Accidental:
                        Accidental accid = (Accidental)obj;
                        Assert.AreNotEqual(Model.AccidType.Null, accid.AccidentalType);
                        break;

                    case ObjectType.Barline:
                        Barline bl = (Barline)obj;
                        Assert.AreNotEqual(Model.BarlineType.Null, bl.BarlineType);
                        break;

                    case ObjectType.Clef:
                        Model.Clef clef = (Model.Clef)obj;
                        Assert.AreNotEqual(Model.Clefshape.Null, clef.Shape);
                        break;

                    case ObjectType.KeyAccidental:
                        KeyAccidental keyacc = (KeyAccidental)obj;
                        Assert.AreNotEqual(Model.AccidType.Null, keyacc.AccidentalType);
                        break;

                    case ObjectType.Mensur:
                        Model.Mensur mens = (Model.Mensur)obj;
                        Assert.AreNotEqual(0, mens.Tempus);
                        break;

                    case ObjectType.Note:
                        Model.Note note = (Model.Note)obj;
                        Assert.AreNotEqual(0, note.WrittenPitch);
                        Assert.AreNotEqual(Model.Duration.Null, note.Duration);
                        break;

                    case ObjectType.Proportion:
                        Proportion prop = (Proportion)obj;
                        Assert.AreNotEqual(0, prop.Num);
                        Assert.AreNotEqual(0, prop.Numbase);
                        break;

                    case ObjectType.Rest:
                        Model.Rest rest = (Model.Rest)obj;
                        Assert.AreNotEqual(Model.Duration.Null, rest.Duration);
                        break;

                    case ObjectType.Custos:
                        break;

                    case ObjectType.Dot:
                        break;

                    case ObjectType.Gap:
                        Model.Gap gap = (Model.Gap)obj;
                        Assert.AreNotEqual(Model.GapType.Null, gap.GapType);
                        break;

                    default:
                        Assert.Fail($"Test of {obj.Type} {obj.ID} failed!");
                        break;
                    }
                }
            }
        }