コード例 #1
0
        public PolylineData(
            IStorageObject storage,
            EditorFile file,
            float constant = 0
            ) :
            base(
                storage.ID,
                file,
                FactoryInstance
                )
        {
            this.storage = storage;

            if (storage.IsEmpty)
            {
                Add(0f, constant);
            }

            listener_add =
                storage.CreateListen(IOEvent.ChildAdded, (key, pt_objID) => {
                var t = float.Parse(key);
                var v = float.Parse(storage.Graph[pt_objID].ReadAllString());

                Add_ram(t, v);
            });

            listener_rekey =
                storage.Graph.CreateListen(
                    msg => {
                var t0 = float.Parse(msg.Relation);
                var t1 = float.Parse(msg.NewRelation);

                MoveX_ram(t0, t1);
            },
                    storage.ID,
                    IOEvent.ChildRekeyed
                    );

            listener_contentsset =
                storage.CreateListen(IOEvent.ChildContentsSet, (key, pt_objID) => {
                var t  = float.Parse(key);
                var v1 = float.Parse(storage.Graph[pt_objID].ReadAllString());

                MoveY_ram(t, v1);
            });

            listener_remove =
                storage.CreateListen(IOEvent.ChildRemoved, (key, pt_objID) => {
                var t = float.Parse(key);
                var v = float.Parse(storage.Graph[pt_objID].ReadAllString());

                RemoveExact_ram(t, v);
            });
        }
コード例 #2
0
 public IFunction Create(
     IFunction context = null,
     IFunction[] args  = null,
     EditorFile file   = null,
     string key        = null,
     params float[] numbers
     ) =>
 new PolylineFunction(
     (file[PolylineContainer.ItemName] as PolylineContainer)
     .Polylines
     [key]
     );
コード例 #3
0
 public Screen(
     StorageObjectID storageobjectID,
     EditorFile file,
     IFactory <IScreen> factory = null
     ) :
     base(
         storageobjectID,
         file,
         factory
         )
 {
 }
コード例 #4
0
 public IFunction Create(
     IFunction context = null,
     IFunction[] args  = null,
     EditorFile file   = null,
     string key        = null,
     params float[] numbers
     ) =>
 new StepwiseIntegratedFunction(
     numbers?.Length == 1 ?
     numbers[0] :
     1 / 256f,
     context
     );
コード例 #5
0
        public FunctionSource(
            StorageObjectID storageobjectID,
            EditorFile file
            ) :
            base(
                storageobjectID,
                file
                )
        {
            this.storageobjectID = storageobjectID;
            container            = file[FunctionContainer.ItemName] as FunctionContainer;

            Setup();
        }
コード例 #6
0
 public BoundList(
     StorageObjectID storageobjectID,
     EditorFile file,
     BoundList <T> master
     ) :
     this(
         storageobjectID,
         file,
         master.factoryset,
         master.viewerset,
         master
         )
 {
 }
コード例 #7
0
        public TimeMarkerUnit(
            IStorageObject storage,
            EditorFile file
            ) :
            base(
                storage.ID,
                file,
                null
                )
        {
            this.storage = storage;

            listener_added =
                storage.CreateListen(IOEvent.ChildAdded, (key, newmarker_objID) => {
                var name = key;
                var time = Time.FromTicks(int.Parse(storage.Graph[newmarker_objID].ReadAllString()));

                markers.Add(name, new ObservableProperty <Time>(time));
            });

            listener_rekeyed =
                storage
                .Graph
                .CreateListen(
                    msg => {
                var oldname = msg.Relation;
                var newname = msg.NewRelation;

                var prop = markers[oldname];
                markers.Remove(oldname);
                markers.Add(newname, prop);
            },
                    storage.ID,
                    IOEvent.ChildRekeyed
                    );

            listener_contentsset =
                storage.CreateListen(IOEvent.ChildContentsSet, (key, marker_objID) => {
                var name    = key;
                var newtime = Time.FromTicks(int.Parse(storage.Graph[marker_objID].ReadAllString()));

                markers[name].Value = newtime;
            });

            listener_removed =
                storage.CreateListen(IOEvent.ChildRemoved, (name, oldmarker_objID) => {
                markers.Remove(name);
            });
        }
コード例 #8
0
            public IFunction Create(
                IFunction context = null,
                IFunction[] args  = null,
                EditorFile file   = null,
                string key        = null,
                params float[] numbers
                )
            {
                if (numbers.Length != 1)
                {
                    throw new ArgumentException();
                }

                return(new PulseWidthModulatedFunction(numbers[0], context));
            }
コード例 #9
0
 public BoundList(
     StorageObjectID storageobjectID,
     EditorFile file,
     FactorySet <T> factoryset,
     ViewerSet <T> viewerset
     ) :
     this(
         storageobjectID,
         file,
         factoryset,
         viewerset,
         null
         )
 {
 }
コード例 #10
0
        public SheetMusicEditor(
            StorageObjectID storageobjectID,
            EditorFile file,
            IFactory <ITrackController> factory
            ) :
            base(
                storageobjectID,
                file,
                factory
                )
        {
            hints = new OverrideTrackControllerHints(this);

            container = file[TrackControllerContainer.ItemName] as TrackControllerContainer;

            Tracks.ItemAdded   += Tracks_ItemAdded;
            Tracks.ItemRemoved += Tracks_ItemRemoved;

            CommandCenter.WhenCursor_Divide   += CommandCenter_WhenCursor_Divide;
            CommandCenter.WhenCursor_Multiply += CommandCenter_WhenCursor_Multiply;
            CommandCenter.WhenCursor_ResetOne += CommandCenter_WhenCursor_ResetOne;

            CommandCenter.WhenSelectAll       += CommandCenter_WhenSelectAll;
            CommandCenter.WhenDeselectAll     += CommandCenter_WhenDeselectAll;
            CommandCenter.WhenToggleSelectAll += CommandCenter_WhenToggleSelectAll;

            CommandCenter.WhenToneChanged        += CommandCenter_WhenToneChanged;
            CommandCenter.WhenTimeChanged        += CommandCenter_WhenTimeChanged;
            CommandCenter.WhenPreviewToneChanged += CommandCenter_WhenPreviewToneChanged;
            CommandCenter.WhenPreviewTimeChanged += CommandCenter_WhenPreviewTimeChanged;
            CommandCenter.WhenToneStart          += CommandCenter_WhenToneStart;
            CommandCenter.WhenTimeStart          += CommandCenter_WhenTimeStart;
            CommandCenter.WhenToneReset          += CommandCenter_WhenToneReset;
            CommandCenter.WhenTimeReset          += CommandCenter_WhenTimeReset;

            CommandCenter.WhenSelectionStart  += CommandCenter_WhenSelectionStart;
            CommandCenter.WhenSelectionFinish += CommandCenter_WhenSelectionFinish;

            CommandCenter.WhenNotePlacementStart  += CommandCenter_WhenNotePlacementStart;
            CommandCenter.WhenNotePlacementFinish += CommandCenter_WhenNotePlacementFinish;

            CommandCenter.WhenDeleteSelection += CommandCenter_WhenDeleteSelection;
            CommandCenter.WhenEraseSelection  += CommandCenter_WhenEraseSelection;

            CommandCenter.WhenUnitPicking += CommandCenter_WhenUnitPicking;

            Pin.Time.ActualTime.AfterChange += Pin_ActualTime_AfterChange;
        }
コード例 #11
0
        public PropertyManager(
            IStorageObject storage,
            EditorFile file
            ) :
            base(
                storage.ID,
                file
                )
        {
            this.storage = storage;

            if (!storage.HasChild("next_id"))
            {
                storage.GetOrMake("next_id").WriteAllString("0");
            }
        }
コード例 #12
0
ファイル: FactorySet.cs プロジェクト: nawalgupta/MusicWriter
        public StorageObjectID Init(
            string type,
            StorageObjectID hub_objID,
            EditorFile file
            )
        {
            var factory =
                Factories.FirstOrDefault(_ => _.Name == type);

            var storageobject =
                file.Storage.CreateObject();

            storageobject.GetOrMake("type").WriteAllString(type);
            factory.Init(storageobject.ID, file);

            return(storageobject.ID);
        }
コード例 #13
0
ファイル: FactorySet.cs プロジェクト: nawalgupta/MusicWriter
        public T Load(
            StorageObjectID storageobjectID,
            EditorFile file
            )
        {
            var obj =
                file.Storage[storageobjectID];

            var type =
                obj
                .Get("type")
                .ReadAllString();

            var factory =
                Factories.FirstOrDefault(_ => _.Name == type);

            return(factory.Load(storageobjectID, file));
        }
コード例 #14
0
        public TrackControllerContainer(
            StorageObjectID storageobjectID,
            EditorFile file,
            IFactory <IContainer> factory,

            FactorySet <ITrack> tracks_factoryset,
            ViewerSet <ITrack> tracks_viewerset,

            FactorySet <ITrackController> controllers_factoryset,
            ViewerSet <ITrackController> controllers_viewerset
            ) :
            base(
                storageobjectID,
                file,
                factory,
                ItemName,
                ItemCodeName
                )
        {
            var obj = file.Storage[storageobjectID];

            settings =
                new TrackControllerSettings(
                    obj.GetOrMake("settings"),
                    file
                    );

            tracks =
                new BoundList <ITrack>(
                    obj.GetOrMake("tracks").ID,
                    file,
                    tracks_factoryset,
                    tracks_viewerset
                    );

            controllers =
                new BoundList <ITrackController>(
                    obj.GetOrMake("controllers").ID,
                    file,
                    controllers_factoryset,
                    controllers_viewerset
                    );
        }
コード例 #15
0
        public Container(
            StorageObjectID storageobjectID,
            EditorFile file,
            IFactory <IContainer> factory,
            string name,
            string codename
            ) :
            base(
                storageobjectID,
                file,
                factory
                )
        {
            Name.Value = name;

            Name.BeforeChange += Name_BeforeChange;

            this.codename = codename;
        }
コード例 #16
0
        public TempoTrack(
            StorageObjectID storageobjectID,
            EditorFile file
            ) :
            base(
                storageobjectID,
                file,
                null     //TODO
                )
        {
            obj = this.Object();

            notelengthdata =
                new PolylineData(
                    obj.GetOrMake("note-length"),
                    file,
                    2
                    );
        }
コード例 #17
0
ファイル: Pin.cs プロジェクト: nawalgupta/MusicWriter
        public Pin(
            StorageObjectID storageobjectID,
            EditorFile file,
            TimeMarkerUnit timemarkerunit
            ) :
            base(
                storageobjectID,
                file,
                null     //TODO
                )
        {
            time = new NamedTime(timemarkerunit);

            //TODO: see if changing time.MarkerName is the right action to do to rename the marker

            var obj = this.Object();

            binder_markername = time.MarkerName.Bind(obj.GetOrMake("marker"));
            binder_offset     = time.Offset.Bind(obj.GetOrMake("offset"));
        }
コード例 #18
0
        public TrackControllerSettings(
            IStorageObject storage,
            EditorFile file
            ) :
            base(
                storage.ID,
                file,
                null
                )
        {
            this.storage = storage;

            propertymanager = new PropertyManager(storage.GetOrMake("property-manager"), file);

            musicbrain = new MusicBrain();
            musicbrain.InsertCog(new NotePerceptualCog());
            musicbrain.InsertCog(new MeasureLayoutPerceptualCog());

            timemarkerunit = new TimeMarkerUnit(storage.GetOrMake("time-markers"), file);

            globalcaret = new GlobalCaret(timemarkerunit);
        }
コード例 #19
0
        public TrackControllerScreen(
            StorageObjectID storageobjectID,
            EditorFile file,
            IFactory <IScreen> factory
            ) :
            base(
                storageobjectID,
                file,
                factory
                )
        {
            container = file[TrackControllerContainer.ItemName] as TrackControllerContainer;

            var obj =
                file.Storage[storageobjectID];

            controllers =
                new BoundList <ITrackController>(
                    obj.GetOrMake("controllers").ID,
                    file,
                    container.Controllers
                    );
        }
コード例 #20
0
        public FunctionEditorScreen(
            StorageObjectID storageobjectID,
            EditorFile file
            ) : base(
                storageobjectID,
                file
                )
        {
            container = file[FunctionContainer.ItemName] as FunctionContainer;

            var obj =
                file.Storage[storageobjectID];

            var activefunctionsource_vec_obj =
                obj.GetOrMake("active-function-source-vec");

            listener_activefunctionsourcefile_add =
                activefunctionsource_vec_obj.CreateListen(IOEvent.ChildAdded, (key, activefunctionsource_objID) => {
                if (ActiveFunctionSourceFile.Value != null)
                {
                    throw new InvalidOperationException();
                }

                ActiveFunctionSourceFile.Value =
                    container.FunctionSources[activefunctionsource_objID];
            });

            listener_activefunctionsourcefile_remove =
                activefunctionsource_vec_obj.CreateListen(IOEvent.ChildRemoved, (key, activefunctionsource_objID) => {
                if (ActiveFunctionSourceFile.Value == null)
                {
                    throw new InvalidOperationException();
                }

                ActiveFunctionSourceFile.Value = null;
            });
        }
コード例 #21
0
 public T Load(
     StorageObjectID storageobjectID,
     EditorFile file
     ) =>
 (T)ctorinfo.Invoke(new object[] { storageobjectID, file, this }.Concat(extraarguments).ToArray());
コード例 #22
0
 public virtual void Init(
     StorageObjectID storageobjectID,
     EditorFile file
     )
 {
 }
コード例 #23
0
        public MelodyTrack(
            StorageObjectID storageobjectID,
            EditorFile file
            ) :
            base(
                storageobjectID,
                file,
                null     //TODO
                )
        {
            obj = this.Object();

            notes_field.GeneralDuration.AfterChange += GeneralDuration_AfterChange;

            next_noteID_obj = obj.GetOrMake("next_noteID");
            listener_nextnodeID_contentsset =
                next_noteID_obj.CreateListen(IOEvent.ObjectContentsSet, () => {
                if (!int.TryParse(next_noteID_obj.ReadAllString(), out next_noteID))
                {
                    next_noteID_obj.WriteAllString("0");
                }
            });

            notes_obj            = obj.GetOrMake("notes");
            listener_notes_added =
                notes_obj.CreateListen(IOEvent.ChildAdded, (key, new_note_objID) => {
                var noteID       = new NoteID(int.Parse(key));
                var new_note_obj = notes_obj.Graph[new_note_objID];
                var contents     = new_note_obj.ReadAllString().Split('\n');
                var duration     = CodeTools.ReadDuration(contents[0]);
                var tone         = new SemiTone(int.Parse(contents[1]));

                var note =
                    new Note(
                        noteID,
                        duration,
                        tone
                        );

                notes_field.Add(noteID, duration);
                notes_lookup.Add(noteID, note);
                FieldChanged?.Invoke(duration);
            });

            listener_notes_changed =
                notes_obj.CreateListen(IOEvent.ChildContentsSet, (key, changed_note_objID) => {
                var noteID       = new NoteID(int.Parse(key));
                var new_note_obj = notes_obj.Graph[changed_note_objID];
                var contents     = new_note_obj.ReadAllString().Split('\n');
                var duration     = CodeTools.ReadDuration(contents[0]);
                var tone         = new SemiTone(int.Parse(contents[1]));

                Note oldnote;
                if (notes_lookup.TryGetValue(noteID, out oldnote))
                {
                    if (oldnote.Duration != duration ||
                        oldnote.Tone != tone)
                    {
                        var newnote =
                            new Note(
                                noteID,
                                duration,
                                tone
                                );

                        var oldnoteduration =
                            oldnote.Duration;

                        notes_lookup[noteID] = newnote;
                        notes_field.Move(noteID, oldnoteduration, duration);
                        FieldChanged?.Invoke(oldnoteduration.Union(duration));
                    }
                }
            });

            listener_notes_removed =
                notes_obj.CreateListen(IOEvent.ChildRemoved, (key, old_note_objID) => {
                var noteID = new NoteID(int.Parse(key));

                var oldnote = notes_lookup[noteID];

                notes_field.Remove(noteID, oldnote.Duration);
                notes_lookup.Remove(noteID);
                FieldChanged?.Invoke(oldnote.Duration);
            });
        }
コード例 #24
0
        public IFunction Parse(
            ref string source,
            EditorFile file,
            List <KeyValuePair <Tuple <int, int>, string> > errors
            )
        {
            IFunction context = null;

            while (!source.StartsWith(";"))
            {
                var name_length = source.IndexOfAny(" \r\f\n\v\t({;".ToCharArray());
                var name        = source.Substring(0, name_length);
                source = source.Substring(name.Length);
                source = source.TrimStart();

                var    num_arguments  = new List <float>();
                var    func_arguments = new List <IFunction>();
                string binary_key     = null;

                if (source.StartsWith("("))
                {
                    var inner_args_length = source.IndexOfAny(")".ToCharArray());
                    var inner_args        = source.Substring(0, inner_args_length);
                    source = source.Substring(inner_args.Length + 1).TrimStart(); // removes the trailing parenthesi too

                    inner_args.Trim();

                    if (inner_args.Length > 0 && inner_args[0] == '@')
                    {
                        binary_key = inner_args.Substring(1);
                    }
                    else
                    {
                        var args = inner_args.Split(',');

                        foreach (var arg in args)
                        {
                            num_arguments.Add(float.Parse(arg.Trim()));
                        }
                    }
                }

                if (source.StartsWith("{"))
                {
                    source = source.Substring(1).TrimStart();

                    while (!source.StartsWith("}"))
                    {
                        var arg =
                            Parse(
                                ref source,
                                file,
                                errors
                                );

                        func_arguments.Add(arg);

                        if (source.StartsWith(";"))
                        {
                            source = source.Substring(1).TrimStart();
                        }
                    }

                    source = source.Substring(1).TrimStart();
                }

                var factory =
                    Factories.FirstOrDefault(fac => fac.CodeName == name);

                if (factory == null)
                {
                    errors.Add(new KeyValuePair <Tuple <int, int>, string>(null, $"Codename \"{name}\" not recognized."));
                }

                if (binary_key != null && binary_key.Count(c => c == '.') > 1)
                {
                    errors.Add(new KeyValuePair <Tuple <int, int>, string>(null, $"Key \"{binary_key}\" has multiple dots."));
                }

                context =
                    factory.Create(
                        context,
                        func_arguments?.ToArray(),
                        file,
                        binary_key,
                        num_arguments?.ToArray()
                        );
            }

            return(context);
        }
コード例 #25
0
        public void Import(
            EditorFile file,
            string filename,
            PorterOptions options
            )
        {
            var midifile = new MidiFile(filename, false);

            var trackcontainer =
                file[TrackControllerContainer.ItemName] as TrackControllerContainer;

            var musictrackfactory =
                trackcontainer
                .Tracks
                .FactorySet
                .Factories
                .FirstOrDefault(_ => _ is MusicTrackFactory)
                .Name;

            for (int track_index = 0; track_index < midifile.Tracks; track_index++)
            {
                var events = midifile.Events.GetTrackEvents(track_index);

                var track =
                    (MusicTrack)trackcontainer.Tracks.Create(musictrackfactory);

                foreach (var e in events)
                {
                    switch (e.CommandCode)
                    {
                    case MidiCommandCode.NoteOn: {
                        var e1 = (NoteOnEvent)e;

                        var start =
                            ImportTime(e1.AbsoluteTime, midifile);

                        var length =
                            ImportTime(e1.NoteLength, midifile);

                        var duration =
                            new Duration {
                            Start  = start,
                            Length = length
                        };

                        track.Melody.AddNote(new SemiTone(e1.NoteNumber - 12), duration);

                        break;
                    }

                    case MidiCommandCode.NoteOff: {
                        var e1 = (NoteEvent)e;

                        break;
                    }

                    case MidiCommandCode.MetaEvent: {
                        var meta = (MetaEvent)e;

                        switch (meta.MetaEventType)
                        {
                        case MetaEventType.Copyright:

                            break;

                        case MetaEventType.CuePoint:

                            break;

                        case MetaEventType.DeviceName:

                            break;

                        case MetaEventType.EndTrack:

                            break;

                        case MetaEventType.KeySignature: {
                            var keysigevent = (KeySignatureEvent)meta;

                            var circle5index = (sbyte)keysigevent.SharpsFlats;

                            Mode mode;

                            switch (keysigevent.MajorMinor)
                            {
                            case 1:
                                mode = Mode.Major;
                                break;

                            case 0:
                                mode = Mode.Minor;
                                break;

                            default:
                                throw new InvalidOperationException();
                            }

                            PitchTransform transform;
                            var            key =
                                CircleOfFifths.Index(circle5index, ChromaticPitchClass.C, out transform);

                            var sig =
                                KeySignature.Create(
                                    key,
                                    transform,
                                    mode
                                    );

                            var start =
                                ImportTime(keysigevent.AbsoluteTime, midifile);

                            track
                            .Adornment
                            .KeySignatures
                            .OverwriteEverythingToRight(
                                sig,
                                start
                                );

                            break;
                        }

                        case MetaEventType.Lyric:

                            break;

                        case MetaEventType.Marker:

                            break;

                        case MetaEventType.MidiChannel:

                            break;

                        case MetaEventType.MidiPort:

                            break;

                        case MetaEventType.ProgramName:

                            break;

                        case MetaEventType.SequencerSpecific:
                            break;

                        case MetaEventType.SequenceTrackName: {
                            var text = (TextEvent)meta;

                            track.Name.Value = text.Text;

                            break;
                        }

                        case MetaEventType.SetTempo:
                            var tempoevent = meta as TempoEvent;
                            // Can midi files have linear varying tempos?
                            // if so, then this code doesn't handle all midis.

                            if (options.PortTempo)
                            {
                                track
                                .Tempo
                                .SetTempo(
                                    ImportTime(tempoevent.AbsoluteTime, midifile),
                                    (float)tempoevent.Tempo / 4
                                    );
                            }

                            break;

                        case MetaEventType.SmpteOffset:

                            break;

                        case MetaEventType.TextEvent:
                            break;

                        case MetaEventType.TimeSignature:
                            var timesigevent = (TimeSignatureEvent)meta;

                            var timesig =
                                new TimeSignature(
                                    new Simple(
                                        timesigevent.Numerator,
                                        timesigevent.Denominator
                                        )
                                    );

                            track
                            .Rhythm
                            .TimeSignatures
                            .OverwriteEverythingToRight(
                                timesig,
                                ImportTime(timesigevent.AbsoluteTime, midifile)
                                );

                            break;

                        case MetaEventType.TrackInstrumentName:

                            break;

                        case MetaEventType.TrackSequenceNumber:

                            break;

                        default:
                            throw new InvalidOperationException();
                        }

                        break;
                    }

                    case MidiCommandCode.PatchChange: {
                        break;
                    }

                    case MidiCommandCode.ControlChange: {
                        break;
                    }

                    default:
                        throw new InvalidOperationException();
                    }
                }
            }
        }
コード例 #26
0
        public void Render(
            StringBuilder builder,
            IFunction function,
            EditorFile file
            )
        {
            var function_contextual =
                function as IContextualFunction;

            var function_mixing =
                function as IMixingFunction;

            var function_parameterized =
                function as IParamaterizedFunction;

            var function_storeddata =
                function as IStoredDataFunction;

            if (function_contextual != null)
            {
                Render(builder, function_contextual.Context, file);
                builder.Append(" ");
            }

            builder.Append(function.Factory.CodeName);

            if (function_storeddata != null)
            {
                builder.Append("(@");
                builder.Append(function_storeddata.BinaryKey(file));
                builder.Append(") ");
            }
            else if (function_parameterized != null)
            {
                builder.Append("(");

                for (int i = 0; i < function_parameterized.Arguments.Length; i++)
                {
                    builder.Append(function_parameterized.Arguments[i]);

                    if (i + 1 != function_parameterized.Arguments.Length)
                    {
                        builder.Append(", ");
                    }
                }

                builder.Append(") ");
            }

            if (function_mixing != null)
            {
                builder.Append("{");

                for (int i = 0; i < function_mixing.Arguments.Length; i++)
                {
                    Render(builder, function_mixing.Arguments[i], file);

                    if (i + 1 != function_mixing.Arguments.Length)
                    {
                        builder.AppendLine(";");
                    }
                }
            }
        }
コード例 #27
0
 public string BinaryKey(EditorFile file) =>
 data.Name.Value;
コード例 #28
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);
                    }
                }
            };
        }
コード例 #29
0
        private BoundList(
            StorageObjectID storageobjectID,
            EditorFile file,
            FactorySet <T> factoryset,
            ViewerSet <T> viewerset,
            BoundList <T> master
            ) :
            base(
                storageobjectID,
                file,
                null     //TODO
                )
        {
            this.factoryset = factoryset;
            this.viewerset  = viewerset;
            this.master     = master;

            hub_obj = File.Storage[StorageObjectID];

            var propertybinders =
                new Dictionary <string, PropertyBinder <string> >();

            listener_add =
                hub_obj.CreateListen(
                    IOEvent.ChildAdded,
                    (key, objID) => {
                int i = int.Parse(key);

                if (Objects.Count > i &&
                    Objects.HasItemAt(i) &&
                    Objects[i].StorageObjectID == objID)
                {
                    return;
                }

                var obj =
                    master == null ?
                    FactorySet.Load(objID, File) :
                    master[objID];

                var namedobj =
                    obj as INamedObject;

                if (namedobj != null)
                {
                    if (master == null)
                    {
                        var name_obj =
                            File
                            .Storage
                            [objID]
                            .GetOrMake("name");

                        var name_val = name_obj.ReadAllString();

                        if (map_name.ContainsKey(name_val))
                        {
                            if (master == null)
                            {
                                if (AutomaticallyAvoidNameCollisionsWithUnderlines)
                                {
                                    name_val += "_";
                                }
                                else
                                {
                                    throw new ArgumentException($"Name \"{name_val}\" already in use.");
                                }
                            }
                        }

                        name_obj.WriteAllString(name_val);

                        var binder = namedobj.Name.Bind(name_obj);
                        namedobj.Name.AfterChange += propertybinders.Rename;
                        propertybinders.Add(binder.Property.Value, binder);
                    }
                }

                if (Objects.Contains(obj))
                {
                    throw new InvalidOperationException();
                }

                Objects.Insert(i, obj);

                if (master == null)
                {
                    if (isallowedtobindobjects)
                    {
                        obj.Bind();
                    }
                }
            }
                    );

            listener_remove =
                hub_obj.CreateListen(
                    IOEvent.ChildRemoved,
                    (key, objID) => {
                var i = int.Parse(key);

                var obj =
                    Objects.FirstOrDefault(_ => _.StorageObjectID == objID);

                if (obj != null)
                {
                    var namedobj =
                        obj as INamedObject;

                    if (namedobj != null)
                    {
                        if (master == null)
                        {
                            namedobj.Name.AfterChange -= propertybinders.Rename;

                            propertybinders[namedobj.Name.Value].Dispose();
                            propertybinders.Remove(namedobj.Name.Value);
                        }
                    }

                    if (master == null)
                    {
                        obj.Unbind();
                    }

                    Objects.Remove(obj);
                }
            }
                    );

            listener_move =
                hub_obj
                .Graph
                .CreateListen(
                    msg => {
                var old_i = int.Parse(msg.Relation);
                var new_i = int.Parse(msg.NewRelation);

                Objects.Move(old_i, new_i);
            },
                    hub_obj.ID,
                    IOEvent.ChildRekeyed
                    );

            Objects.ItemInserted += (obj, i) => {
                if (!hub_obj.HasChild(obj.StorageObjectID))
                {
                    if (master == null)
                    {
                        throw new InvalidOperationException();
                    }

                    hub_obj.Add(i.ToString(), obj.StorageObjectID);
                }

                var namedobj =
                    obj as INamedObject;

                if (namedobj != null)
                {
                    namedobj.Name.BeforeChange += Object_Renaming;
                    namedobj.Name.AfterChange  += Object_Renamed;

                    map_name.Add(namedobj.Name.Value, obj);
                    map_name_inverse.Add(obj, namedobj.Name.Value);
                }

                map_storageobjectID.Add(obj.StorageObjectID, obj);
                map_storageobjectID_inverse.Add(obj, obj.StorageObjectID);
            };

            Objects.ItemWithdrawn += (obj, i) => {
                if (hub_obj.HasChild(obj.StorageObjectID))
                {
                    hub_obj.Remove(obj.StorageObjectID);
                }

                var namedobj =
                    obj as INamedObject;

                if (namedobj != null)
                {
                    namedobj.Name.BeforeChange -= Object_Renaming;
                    namedobj.Name.AfterChange  -= Object_Renamed;

                    namedobj.Name.AfterChange -= propertybinders.Rename;

                    map_name.Remove(namedobj.Name.Value);
                    map_name_inverse.Remove(obj);
                }

                map_storageobjectID.Remove(obj.StorageObjectID);
                map_storageobjectID_inverse.Remove(obj);
            };

            Objects.ItemMoved += (item, oldindex, newindex) => {
                var sign = Math.Sign(newindex - oldindex);

                for (int i = oldindex; i != newindex; i += sign)
                {
                    if (isallowedtobindobjects)
                    {
                        throw new NotImplementedException();
                    }
                    else
                    {
                        // The bound list is still loading items from storage.
                        // The 'moving' is really just initialization to sync with
                        // the back-end store, if the code ran this else clause.
                    }
                }
            };
        }
コード例 #30
0
ファイル: RhythmTrack.cs プロジェクト: nawalgupta/MusicWriter
        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);
                        }
                    }
                }
            };
        }