Esempio n. 1
0
        public DiatonicToneClass KeyOfPitchClass(
            ChromaticPitchClass pitch,
            out PitchTransform displaytransform
            )
        {
            foreach (var keytransformkvp in keytransforms)
            {
                if (SemiToneOfKey(new DiatonicTone(keytransformkvp.Key, 0)).PitchClass == pitch)
                {
                    displaytransform = PitchTransform.Natural;
                    return(keytransformkvp.Key);
                }
            }

            var naturalkey =
                keytransforms
                .Sum(keytransformkvp => keytransformkvp.Value.Steps) > 0 ?
                pitch.GetNaturalKeyClass_PreferSharps() :
                pitch.GetNaturalKeyClass_PreferFlats();

            var naturalpitch =
                naturalkey.GetPitchClass();

            var keytransform =
                this[naturalkey];

            displaytransform = new PitchTransform((int)pitch - (int)naturalpitch);
            return(naturalkey);
        }
Esempio n. 2
0
 public static DiatonicTone Key(
     this KeySignature signature,
     SemiTone tone,
     out PitchTransform transform
     ) =>
 new DiatonicTone(
     signature.KeyOfPitchClass(tone.PitchClass, out transform),
     tone.Octave
     );
Esempio n. 3
0
 public NoteLayout(
     PerceptualNote core,
     int halfline,
     float x,
     float width,
     DiatonicTone key,
     PitchTransform transform
     )
 {
     this.core      = core;
     this.halfline  = halfline;
     this.x         = x;
     this.width     = width;
     this.key       = key;
     this.transform = transform;
 }
Esempio n. 4
0
 public KeySignature(
     PitchTransform transform_c,
     PitchTransform transform_d,
     PitchTransform transform_e,
     PitchTransform transform_f,
     PitchTransform transform_g,
     PitchTransform transform_a,
     PitchTransform transform_b
     )
 {
     this[DiatonicToneClass.C] = transform_c;
     this[DiatonicToneClass.D] = transform_d;
     this[DiatonicToneClass.E] = transform_e;
     this[DiatonicToneClass.F] = transform_f;
     this[DiatonicToneClass.G] = transform_g;
     this[DiatonicToneClass.A] = transform_a;
     this[DiatonicToneClass.B] = transform_b;
 }
Esempio n. 5
0
        public static DiatonicToneClass Index(int i, ChromaticPitchClass basis, out PitchTransform transform)
        {
            var color = Index(i, basis);

            DiatonicToneClass diatonicclass;

            if (i > 0)
            {
                diatonicclass = color.GetNaturalKeyClass_PreferSharps();
            }
            else
            {
                diatonicclass = color.GetNaturalKeyClass_PreferFlats();
            }

            transform = new PitchTransform(diatonicclass.GetPitchClass() - color);

            return(diatonicclass);
        }
Esempio n. 6
0
 public static ChromaticPitchClass Transform(
     this PitchTransform transform,
     ChromaticPitchClass pitch
     ) =>
 (ChromaticPitchClass)(((int)pitch + transform.Steps + 12) % 12);
Esempio n. 7
0
        public AdornmentTrack(
            StorageObjectID storageobjectID,
            EditorFile file
            ) :
            base(
                storageobjectID,
                file
                )
        {
            obj = this.Object();

            binder_staffs =
                Staffs.Bind(
                    obj.GetOrMake("staffs").ID,
                    File
                    );

            binder_staffs.Deserializer = staff_obj => {
                using (var stream = staff_obj.OpenRead()) {
                    using (var br = new BinaryReader(stream)) {
                        var staff = new Staff();

                        staff.Lines          = br.ReadInt32();
                        staff.MiddleHalfLine = br.ReadInt32();
                        staff.Shift          = br.ReadInt32();
                        staff.Clef.BottomKey = new DiatonicTone(br.ReadInt32());
                        staff.Clef.Symbol    = (ClefSymbol)br.ReadInt32();

                        return(staff);
                    }
                }
            };

            binder_staffs.Serializer = (staff_obj, staff) => {
                using (var stream = staff_obj.OpenWrite()) {
                    using (var bw = new BinaryWriter(stream)) {
                        bw.Write(staff.Lines);
                        bw.Write(staff.MiddleHalfLine);
                        bw.Write(staff.Shift);
                        bw.Write(staff.Clef.BottomKey.Tones);
                        bw.Write((int)staff.Clef.Symbol);
                    }
                }
            };

            binder_keysigs =
                KeySignatures.Bind(
                    obj.GetOrMake("key-signatures").ID,
                    File
                    );

            binder_keysigs.Deserializer = keysig_obj => {
                using (var stream = keysig_obj.OpenRead()) {
                    using (var br = new BinaryReader(stream)) {
                        var transform_a = new PitchTransform(br.ReadInt32());
                        var transform_b = new PitchTransform(br.ReadInt32());
                        var transform_c = new PitchTransform(br.ReadInt32());
                        var transform_d = new PitchTransform(br.ReadInt32());
                        var transform_e = new PitchTransform(br.ReadInt32());
                        var transform_f = new PitchTransform(br.ReadInt32());
                        var transform_g = new PitchTransform(br.ReadInt32());

                        var keysig =
                            new KeySignature(
                                transform_c,
                                transform_d,
                                transform_e,
                                transform_f,
                                transform_g,
                                transform_a,
                                transform_b
                                );

                        return(keysig);
                    }
                }
            };

            binder_keysigs.Serializer = (keysig_obj, keysig) => {
                using (var stream = keysig_obj.OpenWrite()) {
                    using (var bw = new BinaryWriter(stream)) {
                        bw.Write(keysig[DiatonicToneClass.A].Steps);
                        bw.Write(keysig[DiatonicToneClass.B].Steps);
                        bw.Write(keysig[DiatonicToneClass.C].Steps);
                        bw.Write(keysig[DiatonicToneClass.D].Steps);
                        bw.Write(keysig[DiatonicToneClass.E].Steps);
                        bw.Write(keysig[DiatonicToneClass.F].Steps);
                        bw.Write(keysig[DiatonicToneClass.G].Steps);
                    }
                }
            };
        }
Esempio n. 8
0
 public SemiTone SemiToneOfKey(DiatonicTone diatone, PitchTransform transform) =>
 transform * (this[diatone.KeyClass] * new SemiTone(diatone.KeyClass.GetPitchClass(), diatone.Octave));
Esempio n. 9
0
        public static KeySignature Create(
            DiatonicToneClass key,
            PitchTransform transform,
            Mode mode
            )
        {
            var modesteps = new PitchTransform[] {
                PitchTransform.DoubleSharp,
                PitchTransform.DoubleSharp,
                PitchTransform.Sharp,
                PitchTransform.DoubleSharp,
                PitchTransform.DoubleSharp,
                PitchTransform.DoubleSharp,
                PitchTransform.Sharp
            };

            var keysteps = new PitchTransform[] {
                PitchTransform.DoubleSharp,
                PitchTransform.DoubleSharp,
                PitchTransform.Sharp,
                PitchTransform.DoubleSharp,
                PitchTransform.DoubleSharp,
                PitchTransform.DoubleSharp,
                PitchTransform.Sharp
            };

            var mode_copy = mode;

            while (mode_copy != Mode.Major)
            {
                // rotate L one step
                var step0 = modesteps[0];
                for (int i = 1; i < modesteps.Length; i++)
                {
                    modesteps[i - 1] = modesteps[i];
                }
                modesteps[modesteps.Length - 1] = step0;

                mode_copy = (Mode)((int)mode_copy - 1);
            }

            var key_copy = key;

            while (key_copy != DiatonicToneClass.C)
            {
                // rotate L one step
                var step0 = keysteps[0];
                for (int i = 1; i < keysteps.Length; i++)
                {
                    keysteps[i - 1] = keysteps[i];
                }
                keysteps[keysteps.Length - 1] = step0;

                key_copy = (DiatonicToneClass)((int)key_copy - 1);
            }

            var signature =
                new KeySignature();

            var pitch = key.GetPitchClass();

            for (int i = 0; i < 7; i++)
            {
                signature[key] = transform;

                transform += modesteps[i];
                transform -= keysteps[i];

                //TODO: should modesteps[i] or transform be used here
                pitch = modesteps[i].Transform(pitch);
                key   = key.ToRight();
            }

            return(signature);
        }