public static UProject Load(StreamReader reader, string file) { var project = new UProject() { resolution = 480, FilePath = file, Saved = false }; Ustx.AddDefaultExpressions(project); project.tracks.Add(new UTrack { TrackNo = 0, }); var part = new UVoicePart() { trackNo = 0, position = 0, name = Path.GetFileNameWithoutExtension(file), }; project.parts.Add(part); var blocks = ReadBlocks(reader, file); ParsePart(project, part, blocks); part.Duration = part.notes.Select(note => note.End).Max() + project.resolution; return(project); }
public static void LoadProject(string[] files) { if (files.Length < 1) { return; } ProjectFormats format = DetectProjectFormat(files[0]); UProject project; switch (format) { case ProjectFormats.Ustx: project = Ustx.Load(files[0]); break; case ProjectFormats.Vsq3: case ProjectFormats.Vsq4: project = VSQx.Load(files[0]); break; case ProjectFormats.Ust: project = Ust.Load(files); break; default: throw new FileFormatException("Unknown file format"); } if (project != null) { DocManager.Inst.ExecuteCmd(new LoadProjectNotification(project)); } }
public static void ImportTracks(UProject project, string[] files) { if (files.Length < 1) { return; } foreach (string file in files) { ProjectFormats format = DetectProjectFormat(file); UProject loaded; switch (format) { case ProjectFormats.Ustx: loaded = Ustx.Load(file); break; case ProjectFormats.Vsq3: case ProjectFormats.Vsq4: loaded = VSQx.Load(file); break; case ProjectFormats.Ust: loaded = Ust.Load(new[] { file }); break; default: throw new FileFormatException("Unknown file format"); } int trackCount = project.tracks.Count; foreach (var(abbr, descriptor) in loaded.expressions) { if (!project.expressions.ContainsKey(abbr)) { project.expressions.Add(abbr, descriptor); } } foreach (var track in loaded.tracks) { track.TrackNo = project.tracks.Count; project.tracks.Add(track); } foreach (var part in loaded.parts) { project.parts.Add(part); part.trackNo += trackCount; } project.beatPerBar = loaded.beatPerBar; project.beatUnit = loaded.beatUnit; project.bpm = loaded.bpm; } project.AfterLoad(); project.Validate(); DocManager.Inst.ExecuteCmd(new LoadProjectNotification(project)); }
public static UProject Load(string file) { XmlDocument vsqx = new XmlDocument(); vsqx.Load(file); XmlNamespaceManager nsmanager = new XmlNamespaceManager(vsqx.NameTable); nsmanager.AddNamespace("v3", vsq3NameSpace); nsmanager.AddNamespace("v4", vsq4NameSpace); XmlNode root; string nsPrefix; // Detect vsqx version if ((root = vsqx.SelectSingleNode("v3:vsq3", nsmanager)) != null) { nsPrefix = "v3:"; } else if ((root = vsqx.SelectSingleNode("v4:vsq4", nsmanager)) != null) { nsPrefix = "v4:"; } else { throw new FileFormatException("Unrecognizable VSQx file format."); } UProject uproject = new UProject(); Ustx.AddDefaultExpressions(uproject); uproject.RegisterExpression(new UExpressionDescriptor("opening", "ope", 0, 100, 100)); string bpmPath = $"{nsPrefix}masterTrack/{nsPrefix}tempo/{nsPrefix}{(nsPrefix == "v3:" ? "bpm" : "v")}"; string beatperbarPath = $"{nsPrefix}masterTrack/{nsPrefix}timeSig/{nsPrefix}{(nsPrefix == "v3:" ? "nume" : "nu")}"; string beatunitPath = $"{nsPrefix}masterTrack/{nsPrefix}timeSig/{nsPrefix}{(nsPrefix == "v3:" ? "denomi" : "de")}"; string premeasurePath = $"{nsPrefix}masterTrack/{nsPrefix}preMeasure"; string resolutionPath = $"{nsPrefix}masterTrack/{nsPrefix}resolution"; string projectnamePath = $"{nsPrefix}masterTrack/{nsPrefix}seqName"; string projectcommentPath = $"{nsPrefix}masterTrack/{nsPrefix}comment"; string trackPath = $"{nsPrefix}vsTrack"; string tracknamePath = $"{nsPrefix}{(nsPrefix == "v3:" ? "trackName" : "name")}"; string trackcommentPath = $"{nsPrefix}comment"; string tracknoPath = $"{nsPrefix}{(nsPrefix == "v3:" ? "vsTrackNo" : "tNo")}"; string partPath = $"{nsPrefix}{(nsPrefix == "v3:" ? "musicalPart" : "vsPart")}"; string partnamePath = $"{nsPrefix}{(nsPrefix == "v3:" ? "partName" : "name")}"; string partcommentPath = $"{nsPrefix}comment"; string notePath = $"{nsPrefix}note"; string postickPath = $"{nsPrefix}{(nsPrefix == "v3:" ? "posTick" : "t")}"; string durtickPath = $"{nsPrefix}{(nsPrefix == "v3:" ? "durTick" : "dur")}"; string notenumPath = $"{nsPrefix}{(nsPrefix == "v3:" ? "noteNum" : "n")}"; string velocityPath = $"{nsPrefix}{(nsPrefix == "v3:" ? "velocity" : "v")}"; string lyricPath = $"{nsPrefix}{(nsPrefix == "v3:" ? "lyric" : "y")}"; string phonemePath = $"{nsPrefix}{(nsPrefix == "v3:" ? "phnms" : "p")}"; string playtimePath = $"{nsPrefix}playTime"; string partstyleattrPath = $"{nsPrefix}{(nsPrefix == "v3:" ? "partStyle" : "pStyle")}/{nsPrefix}{(nsPrefix == "v3:" ? "attr" : "v")}"; string notestyleattrPath = $"{nsPrefix}{(nsPrefix == "v3:" ? "noteStyle" : "nStyle")}/{nsPrefix}{(nsPrefix == "v3:" ? "attr" : "v")}"; uproject.bpm = Convert.ToDouble(root.SelectSingleNode(bpmPath, nsmanager).InnerText) / 100; uproject.beatPerBar = int.Parse(root.SelectSingleNode(beatperbarPath, nsmanager).InnerText); uproject.beatUnit = int.Parse(root.SelectSingleNode(beatunitPath, nsmanager).InnerText); uproject.resolution = int.Parse(root.SelectSingleNode(resolutionPath, nsmanager).InnerText); uproject.FilePath = file; uproject.name = root.SelectSingleNode(projectnamePath, nsmanager).InnerText; uproject.comment = root.SelectSingleNode(projectcommentPath, nsmanager).InnerText; int preMeasure = int.Parse(root.SelectSingleNode(premeasurePath, nsmanager).InnerText); int partPosTickShift = -preMeasure * uproject.resolution * uproject.beatPerBar * 4 / uproject.beatUnit; USinger usinger = new USinger(""); foreach (XmlNode track in root.SelectNodes(trackPath, nsmanager)) // track { UTrack utrack = new UTrack() { Singer = usinger, TrackNo = uproject.tracks.Count }; uproject.tracks.Add(utrack); //utrack.Name = track.SelectSingleNode(tracknamePath, nsmanager).InnerText; //utrack.Comment = track.SelectSingleNode(trackcommentPath, nsmanager).InnerText; utrack.TrackNo = int.Parse(track.SelectSingleNode(tracknoPath, nsmanager).InnerText); foreach (XmlNode part in track.SelectNodes(partPath, nsmanager)) // musical part { UVoicePart upart = new UVoicePart(); uproject.parts.Add(upart); upart.name = part.SelectSingleNode(partnamePath, nsmanager).InnerText; upart.comment = part.SelectSingleNode(partcommentPath, nsmanager).InnerText; upart.position = int.Parse(part.SelectSingleNode(postickPath, nsmanager).InnerText) + partPosTickShift; upart.Duration = int.Parse(part.SelectSingleNode(playtimePath, nsmanager).InnerText); upart.trackNo = utrack.TrackNo; foreach (XmlNode note in part.SelectNodes(notePath, nsmanager)) { UNote unote = uproject.CreateNote(); unote.position = int.Parse(note.SelectSingleNode(postickPath, nsmanager).InnerText); unote.duration = int.Parse(note.SelectSingleNode(durtickPath, nsmanager).InnerText); unote.tone = int.Parse(note.SelectSingleNode(notenumPath, nsmanager).InnerText); unote.lyric = note.SelectSingleNode(lyricPath, nsmanager).InnerText; if (unote.lyric == "-") { unote.lyric = "..."; } unote.phonemeExpressions.Add(new UExpression("vel") { index = 0, value = int.Parse(note.SelectSingleNode(velocityPath, nsmanager).InnerText) * 100 / 64, }); foreach (XmlNode notestyle in note.SelectNodes(notestyleattrPath, nsmanager)) { if (notestyle.Attributes["id"].Value == "opening") { unote.phonemeExpressions.Add(new UExpression("ope") { index = 0, value = int.Parse(notestyle.InnerText) * 100 / 127, }); } else if (notestyle.Attributes["id"].Value == "accent") { unote.phonemeExpressions.Add(new UExpression("atk") { index = 0, value = int.Parse(notestyle.InnerText) * 2, }); } else if (notestyle.Attributes["id"].Value == "decay") { unote.phonemeExpressions.Add(new UExpression("dec") { index = 0, // V4 default is 50. Translate it to no effect in OU. V4 dec 100 roughly maps to OU 50. value = Math.Max(0, int.Parse(notestyle.InnerText) - 50), }); } } unote.pitch.data[0].X = -(float)uproject.TickToMillisecond(Math.Min(15, unote.duration / 3)); unote.pitch.data[1].X = -unote.pitch.data[0].X; upart.notes.Add(unote); } } } uproject.AfterLoad(); uproject.Validate(); return(uproject); }