public void AddConstant(float t, float value) { var i = bsearch_time_left(t); float?t1 = i + 1 != times.Count ? times[i] - (1 / 256f) : default(float?); if (!storage.HasChild(t.ToString())) { var pt0_obj = storage.Graph.CreateObject(); pt0_obj.WriteAllString(value.ToString()); storage.Add(t.ToString(), pt0_obj.ID); } else { storage .Get(t.ToString()) .WriteAllString(value.ToString()); } if (t1.HasValue) { var pt1_obj = storage.Graph.CreateObject(); pt1_obj.WriteAllString(value.ToString()); storage.Add(t1.Value.ToString(), pt1_obj.ID); } }
public MusicTrack( EditorFile file, IStorageObject storage, TrackControllerSettings settings ) : base( storage.ID, file ) { melody = new MelodyTrack(storage.GetOrMake("melody").ID, file); rhythm = new RhythmTrack(storage.GetOrMake("rhythm").ID, file); adornment = new AdornmentTrack(storage.GetOrMake("adornment").ID, file); tempo = new TempoTrack(storage.GetOrMake("tempo").ID, file); memory = new PerceptualMemory(); propertygraphlet = new StoragePropertyGraphlet <NoteID>(storage, propertymanager); propertymanager = settings.PropertyManager; this.settings = settings; melody.FieldChanged += Melody_FieldChanged; rhythm.MeterSignatures.FieldChanged += MeterSignatures_FieldChanged; rhythm.TimeSignatures.FieldChanged += TimeSignatures_FieldChanged; adornment.KeySignatures.FieldChanged += KeySignatures_FieldChanged; adornment.Staffs.FieldChanged += Staffs_FieldChanged; if (!storage.HasChild("state") || storage.Get("state").ReadAllString() != "inited") { Init(); storage.GetOrMake("state").WriteAllString("inited"); } Init_memory(); }
private void Field_ItemAdded( Duration duration, T value ) { var relation = CodeTools.WriteDuration(duration); events.Add(duration); if (!obj.HasChild(relation)) { var item_objID = File.Storage.Create(); Serializer(File.Storage[item_objID], value); obj.Add(relation, item_objID); } }
public PropertyManager( IStorageObject storage, EditorFile file ) : base( storage.ID, file ) { this.storage = storage; if (!storage.HasChild("next_id")) { storage.GetOrMake("next_id").WriteAllString("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. } } }; }