示例#1
0
 public PerceptualNoteID(
     NoteID noteID,
     int instance
     )
 {
     NoteID   = noteID;
     Instance = instance;
 }
示例#2
0
 public Note(
     NoteID id,
     Duration duration,
     SemiTone tone
     )
 {
     this.id       = id;
     this.duration = duration;
     this.tone     = tone;
 }
示例#3
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);
        }
示例#4
0
        public void CommandCenter_WhenDeleteSelectedNotes()
        {
            var effectedarea = default(Duration);

            foreach (var selectionkvp in NoteSelections)
            {
                var track =
                    selectionkvp.Key;

                var selection =
                    new NoteID[0]
                    .Concat(selectionkvp.Value.Selected_End)
                    .Concat(selectionkvp.Value.Selected_Start)
                    .Concat(selectionkvp.Value.Selected_Tone)
                    .Distinct()
                    .ToArray();

                foreach (var noteID in selection)
                {
                    var note = track.Melody[noteID];

                    track.Melody.DeleteNote(noteID);

                    if (selectionkvp.Value.Selected_Start.Contains(noteID))
                    {
                        selectionkvp.Value.Selected_Start.Remove(noteID);
                    }
                    if (selectionkvp.Value.Selected_End.Contains(noteID))
                    {
                        selectionkvp.Value.Selected_End.Remove(noteID);
                    }
                    if (selectionkvp.Value.Selected_Tone.Contains(noteID))
                    {
                        selectionkvp.Value.Selected_Tone.Remove(noteID);
                    }

                    effectedarea = note.Duration.Union(effectedarea);
                }
            }

            if (effectedarea != null)
            {
                InvalidateTime(effectedarea);
            }

            Refresh();
        }
示例#5
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);
            });
        }
示例#6
0
 public Note this[NoteID noteID] {
     get { return(notes_lookup[noteID]); }
     set { UpdateNote(noteID, value.Duration, value.Tone); }
 }
示例#7
0
 public bool TryGetNote(NoteID noteID, out Note note) =>
 notes_lookup.TryGetValue(noteID, out note);
示例#8
0
 public bool HasNoteID(NoteID noteID) =>
 notes_lookup.ContainsKey(noteID);
示例#9
0
        public void DeleteNote(NoteID noteID)
        {
            var note_objID = notes_obj[noteID.ToString()];

            notes_obj.Graph.Delete(note_objID);
        }
示例#10
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}");
        }