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(); }
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); }
public PropertyManager( IStorageObject storage, EditorFile file ) : base( storage.ID, file ) { this.storage = storage; if (!storage.HasChild("next_id")) { storage.GetOrMake("next_id").WriteAllString("0"); } }
public Property Access(string name, object @default = null) { Property property; if (!properties.TryGetValue(name, out property)) { var obj = storage.GetOrMake(name); if (obj.IsEmpty) { obj.WriteAllString(next_id++.ToString()); } properties.Add(name, property = new Property(name, @default, int.Parse(obj.ReadAllString()))); } return(property); }
public TempoTrack( StorageObjectID storageobjectID, EditorFile file ) : base( storageobjectID, file, null //TODO ) { obj = this.Object(); notelengthdata = new PolylineData( obj.GetOrMake("note-length"), file, 2 ); }
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); }); }
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); } } }; }
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); } } } }; }