private Measure ParseMeasure(string input) { try { var ms = new Measure(); if (input.Contains(":")) { var options = input.Split(':'); foreach (var opt in options) { var info = opt.Trim(); if (info.StartsWith("Time-")) { ms.TimeSignature = TimeSignatures.GetTime(info.Substring(5)); } else if (info.StartsWith("Key-")) { ms.KeySignature = KeySignatures.GetKey(info.Substring(4)); } else if (info.StartsWith("Clef-")) { ms.Clef = Clefs.GetClef(info.Substring(5)); } } input = options.Last(); } var units = input.Split(','); foreach (var unit in units) { var p = unit.Trim().ToUpperInvariant(); if ((!p.EndsWith("QUARTER") && p.EndsWith("R")) || p.EndsWith("REST")) { ms.Pattern.Add(new Rest(p)); } else { ms.Pattern.Add(new Note(p)); } } return(ms); } catch (Exception ex) { throw new UnrecognizedPatternException($"Unrecognized Measure: {input}", ex); } }
public override void ReadSong() { //HEADERS //VERSION Version = ReadVersion(); VersionTuple = ReadVersionTuple(); //INFORMATION ABOUT THE PIECE ReadInfo(); TripletFeel = GpBase.ReadBool()[0] ? TripletFeels.Eigth : TripletFeels.None; //readLyrics(); Tempo = GpBase.ReadInt()[0]; Key = (KeySignatures)(GpBase.ReadInt()[0] * 10); //key + 0 //GpBase.readSignedByte(); //octave ReadMidiChannels(); MeasureCount = GpBase.ReadInt()[0]; TrackCount = GpBase.ReadInt()[0]; ReadMeasureHeaders(MeasureCount); ReadTracks(TrackCount, Channels); ReadMeasures(); }
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); } } }; }