Beispiel #1
0
        private void Storage_ChildRekeyed(IOMessage message)
        {
            var oldduration = CodeTools.ReadDuration(message.Relation);
            var newduration = CodeTools.ReadDuration(message.NewRelation);

            field.TryMoveUnique(oldduration, newduration);
        }
Beispiel #2
0
        private void Storage_ChildRemoved(string key, StorageObjectID child)
        {
            var duration =
                CodeTools.ReadDuration(key);

            if (field.HasItem(duration))
            {
                field.RemoveUnique(duration);
            }
        }
Beispiel #3
0
        private void Field_ItemChanged(
            Duration duration,
            T oldvalue,
            T newvalue
            )
        {
            var relation =
                CodeTools.WriteDuration(duration);

            Serializer(obj.Get(relation), newvalue);
        }
Beispiel #4
0
        private void Storage_ChildContentsSet(string key, StorageObjectID child)
        {
            var duration =
                CodeTools.ReadDuration(key);

            var contents =
                Deserializer(File.Storage[child]);

            if (field.HasItem(duration))
            {
                field.UpdateUnique(duration, contents);
            }
        }
Beispiel #5
0
        public NoteID AddNote(SemiTone tone, Duration duration)
        {
            var noteID = new NoteID(next_noteID++);

            next_noteID_obj.WriteAllString(next_noteID.ToString());

            var newnote_obj = notes_obj.Graph[notes_obj.Graph.Create()];

            newnote_obj.WriteAllString($"{CodeTools.WriteDuration(duration)}\n{tone.Semitones}");

            notes_obj.Add(noteID.ToString(), newnote_obj.ID);

            return(noteID);
        }
Beispiel #6
0
        private void Field_ItemRemoved(
            Duration duration,
            T value
            )
        {
            var relation =
                CodeTools.WriteDuration(duration);

            events.Remove(duration);

            if (obj.HasChild(relation))
            {
                obj.Get(relation).Delete();
            }
        }
Beispiel #7
0
        private void Field_ItemMoved(
            Duration oldduration,
            Duration newduration,
            T value
            )
        {
            var oldrelation =
                CodeTools.WriteDuration(oldduration);

            events.Remove(oldduration);
            events.Add(newduration);

            if (obj.HasChild(oldrelation))
            {
                obj.Rename(oldrelation, CodeTools.WriteDuration(newduration));
            }
        }
Beispiel #8
0
        private void Storage_ChildAdded(string key, StorageObjectID child)
        {
            var duration =
                CodeTools.ReadDuration(key);

            if (!events.Contains(duration))
            {
                lock (locker) {
                    if (events.Contains(duration))
                    {
                        return;
                    }
                    events.Add(duration);
                }

                var contents = Deserializer(File.Storage[child]);
                field.Add(contents, duration);
            }
        }
Beispiel #9
0
        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);
            }
        }
Beispiel #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);
            });
        }
Beispiel #11
0
        public void UpdateNote(NoteID noteID, Duration newduration, SemiTone newtone)
        {
            var note_obj = notes_obj.Get(noteID.ToString());

            note_obj.WriteAllString($"{CodeTools.WriteDuration(newduration)}\n{newtone}");
        }