Ejemplo n.º 1
0
        public DurationFieldBinder(
            StorageObjectID storageobjectID,
            EditorFile file,
            DurationField <T> field
            ) :
            base(
                storageobjectID,
                file,
                null     //TODO
                )
        {
            this.field = field;

            obj = this.Object();

            field.ItemAdded   += Field_ItemAdded;
            field.ItemMoved   += Field_ItemMoved;
            field.ItemChanged += Field_ItemChanged;
            field.ItemRemoved += Field_ItemRemoved;

            listener_added       = obj.CreateListen(IOEvent.ChildAdded, Storage_ChildAdded);
            listener_rekeyed     = obj.Graph.CreateListen(Storage_ChildRekeyed, storageobjectID, IOEvent.ChildRekeyed);
            listener_contentsset = obj.CreateListen(IOEvent.ChildContentsSet, Storage_ChildContentsSet);
            listener_removed     = obj.CreateListen(IOEvent.ChildRemoved, Storage_ChildRemoved);
        }
Ejemplo n.º 2
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);
            });
        }
        private void Listeners_ItemInserted(IOListener listener, int i)
        {
            var j = messages.Count - 1;

            readylisteners.Insert(i, j);

            for (; j >= 0; j--)
            {
                listener.Process(messages[j]);
            }
        }
Ejemplo n.º 4
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);
            });
        }
Ejemplo n.º 5
0
        public PropertyBinder(
            IStorageObject storageobject,
            ObservableProperty <T> property,
            Func <IStorageObject, T> deserializer,
            Action <IStorageObject, T> serializer
            )
        {
            this.storageobject = storageobject;
            this.property      = property;
            this.deserializer  = deserializer;
            this.serializer    = serializer;

            listener              = storageobject.CreateListen(IOEvent.ObjectContentsSet, StorageObject_ContentsSet);
            property.AfterChange += Property_AfterChange;

            storageobject.Graph.Listeners.Add(listener);
        }
Ejemplo n.º 6
0
        private void Listeners_ItemInserted(IOListener listener, int i)
        {
            int[] indicies_msg;

            lock (locker) {
                var lookup_subject_this =
                    lookup_subject.Lookup(
                        listener.Filter.Subject,
                        () =>
                        new KeyValuePair <ShiftableBitArray, ShiftableBitArray>(
                            new ShiftableBitArray(),
                            new ShiftableBitArray()
                            )
                        );

                var lookup_verb_this =
                    lookup_verb.Lookup(
                        listener.Filter.Verb,
                        () =>
                        new KeyValuePair <ShiftableBitArray, ShiftableBitArray>(
                            new ShiftableBitArray(),
                            new ShiftableBitArray()
                            )
                        );

                foreach (var subject in lookup_subject)
                {
                    subject.Value.Key.Insert(i, subject.Key == listener.Filter.Subject);
                }

                foreach (var verb in lookup_verb)
                {
                    verb.Value.Key.Insert(i, verb.Key == listener.Filter.Verb);
                }

                indicies_msg = lookup_subject_this.Value.AllOnes(lookup_verb_this.Value).ToArray();
            }

            for (int j = 0; j < indicies_msg.Length; j++)
            {
                listener.Responder(Messages[indicies_msg[j]]);
            }
        }
Ejemplo n.º 7
0
        private void Listeners_ItemWithdrawn(IOListener listener, int i)
        {
            lock (locker) {
                var lookup_subject_this =
                    lookup_subject[listener.Filter.Subject];

                var lookup_verb_this =
                    lookup_verb[listener.Filter.Verb];

                foreach (var subject in lookup_subject)
                {
                    subject.Value.Key.Withdraw(i);
                }

                foreach (var verb in lookup_verb)
                {
                    verb.Value.Key.Withdraw(i);
                }
            }
        }
Ejemplo n.º 8
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;
            });
        }
Ejemplo n.º 9
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.
                    }
                }
            };
        }
Ejemplo n.º 10
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);
            });
        }
Ejemplo n.º 11
0
 private void Listeners_ItemWithdrawn(IOListener listener, int i)
 {
     //this is unsafe
     readylisteners.RemoveAt(i);
 }