Esempio n. 1
0
        public static string Serialize()
        {
            var dto = new MusicDTO.EditData();

            dto.BPM      = EditData.BPM.Value;
            dto.maxBlock = EditData.MaxBlock.Value;
            dto.offset   = EditData.OffsetSamples.Value;
            dto.name     = Path.GetFileNameWithoutExtension(EditData.Name.Value);

            var sortedNoteObjects = EditData.Notes.Values
                                    .Where(note => !(note.note.type == NoteTypes.Long && EditData.Notes.ContainsKey(note.note.prev)))
                                    .OrderBy(note => note.note.position.ToSamples(Audio.Source.clip.frequency, EditData.BPM.Value));

            dto.notes = new List <MusicDTO.Note>();

            foreach (var noteObject in sortedNoteObjects)
            {
                if (noteObject.note.type == NoteTypes.Single)
                {
                    dto.notes.Add(ToDTO(noteObject));
                }
                else if (noteObject.note.type == NoteTypes.Long)
                {
                    var current = noteObject;
                    var note    = ToDTO(noteObject);

                    while (EditData.Notes.ContainsKey(current.note.next))
                    {
                        var nextObj = EditData.Notes[current.note.next];
                        note.notes.Add(ToDTO(nextObj));
                        current = nextObj;
                    }

                    dto.notes.Add(note);
                }
            }

            var jsonWriter = new JsonWriter();

            jsonWriter.PrettyPrint = true;
            jsonWriter.IndentValue = 4;
            JsonMapper.ToJson(dto, jsonWriter);
            return(jsonWriter.ToString());
        }
 public MusicDTOFormatter(MusicListItemJson item, MusicInf inf, MusicDTO.EditData data)
 {
     this.item = item;
     this.inf  = inf;
     dto_data  = data;
 }