Example #1
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);
                    }
                }
            };
        }
Example #2
0
        public RhythmTrack(
            StorageObjectID storageobjectID,
            EditorFile file
            ) :
            base(
                storageobjectID,
                file,
                null     //TOOD
                )
        {
            obj = this.Object();

            binder_timesignatures =
                TimeSignatures.Bind(
                    obj.GetOrMake("time-signatures").ID,
                    file
                    );

            binder_timesignatures.Deserializer = timesig_obj => {
                using (var stream = timesig_obj.OpenRead()) {
                    using (var br = new BinaryReader(stream)) {
                        var simples = new Simple[br.ReadInt32()];

                        for (int i = 0; i < simples.Length; i++)
                        {
                            var upper = br.ReadInt32();
                            var lower = br.ReadInt32();

                            simples[i] = new Simple(upper, lower);
                        }

                        return(new TimeSignature(simples));
                    }
                }
            };

            binder_timesignatures.Serializer = (timesig_obj, timesig) => {
                using (var stream = timesig_obj.OpenWrite()) {
                    using (var bw = new BinaryWriter(stream)) {
                        bw.Write(timesig.Simples.Count);

                        for (int i = 0; i < timesig.Simples.Count; i++)
                        {
                            var simple = timesig.Simples[i];

                            bw.Write(simple.Upper);
                            bw.Write(simple.Lower);
                        }
                    }
                }
            };

            binder_metersignatures =
                MeterSignatures.Bind(
                    obj.GetOrMake("meter-signatures").ID,
                    file
                    );

            binder_metersignatures.Deserializer = metersig_obj => {
                using (var stream = metersig_obj.OpenRead()) {
                    using (var br = new BinaryReader(stream)) {
                        var cells = new Cell[br.ReadInt32()];

                        for (int i = 0; i < cells.Length; i++)
                        {
                            var length = Time.FromTicks(br.ReadInt32());
                            var stress = br.ReadSingle();

                            cells[i] = new Cell {
                                Length = length,
                                Stress = stress
                            };
                        }

                        var totallength =
                            cells.Aggregate(
                                Time.Zero,
                                (acc, cell) => acc + cell.Length
                                );

                        return(new MeterSignature(totallength, cells));
                    }
                }
            };

            binder_metersignatures.Serializer = (metersig_obj, metersig) => {
                using (var stream = metersig_obj.OpenWrite()) {
                    using (var bw = new BinaryWriter(stream)) {
                        bw.Write(metersig.Cells.Count);

                        for (int i = 0; i < metersig.Cells.Count; i++)
                        {
                            var cell = metersig.Cells[i];

                            bw.Write(cell.Length.Ticks);
                            bw.Write(cell.Stress);
                        }
                    }
                }
            };
        }