/// <summary> /// Converts a time value into a tick position value. May be inaccurate due to interger rounding. /// </summary> /// <param name="time">The time (in seconds) to convert.</param> /// <param name="resolution">Ticks per beat, usually provided from the resolution song of a Song class.</param> /// <returns>Returns the calculated tick position.</returns> public uint TimeToTick(float time, float resolution, bool capByLength = true) { if (time < 0) { time = 0; } else if (capByLength && time > length) { time = length; } uint position = 0; BPM prevBPM = bpms[0]; // Search for the last bpm for (int i = 0; i < bpms.Count; ++i) { BPM bpmInfo = bpms[i]; if (bpmInfo.assignedTime >= time) { break; } else { prevBPM = bpmInfo; } } position = prevBPM.tick; position += TickFunctions.TimeToDis(prevBPM.assignedTime, time, resolution, prevBPM.value / 1000.0f); return(position); }
public IEnumerator _ExportSong(string filepath) { // Start saving Globals.applicationMode = Globals.ApplicationMode.Loading; loadingScreen.FadeIn(); loadingScreen.loadingInformation.text = "Exporting " + exportOptions.format; Song song = new Song(editor.currentSong); exportOptions.tickOffset = TickFunctions.TimeToDis(0, delayTime, exportOptions.targetResolution, 120); float timer = Time.realtimeSinceStartup; string errorMessageList = string.Empty; Thread exportingThread = new Thread(() => { if (exportOptions.format == ExportOptions.Format.Chart) { try { new ChartWriter(filepath).Write(song, exportOptions, out errorMessageList); //song.Save(filepath, exportOptions); } catch (System.Exception e) { Logger.LogException(e, "Error when exporting chart"); errorMessageList += e.Message; } } else if (exportOptions.format == ExportOptions.Format.Midi) { try { MidWriter.WriteToFile(filepath, song, exportOptions); } catch (System.Exception e) { Logger.LogException(e, "Error when exporting midi"); errorMessageList += e.Message; } } }); exportingThread.Start(); while (exportingThread.ThreadState == ThreadState.Running) { yield return(null); } if (generateIniToggle.isOn) { loadingScreen.loadingInformation.text = "Generating Song.ini"; Thread iniThread = new Thread(() => { GenerateSongIni(Path.GetDirectoryName(filepath)); }); iniThread.Start(); while (iniThread.ThreadState == ThreadState.Running) { yield return(null); } } Debug.Log("Total exporting time: " + (Time.realtimeSinceStartup - timer)); // Stop loading animation loadingScreen.FadeOut(); loadingScreen.loadingInformation.text = "Complete!"; if (errorMessageList != string.Empty) { ChartEditor.Instance.errorManager.QueueErrorMessage("Encountered the following errors while exporting: " + Globals.LINE_ENDING + errorMessageList); } }
public IEnumerator _ExportSong(string filepath) { LoadingTasksManager tasksManager = editor.services.loadingTasksManager; Song song = editor.currentSong;// new Song(editor.currentSong); exportOptions.tickOffset = TickFunctions.TimeToDis(0, delayTime, exportOptions.targetResolution, 120); float timer = Time.realtimeSinceStartup; string errorMessageList = string.Empty; List <LoadingTask> tasks = new List <LoadingTask>() { new LoadingTask("Exporting " + exportOptions.format, () => { if (exportOptions.format == ExportOptions.Format.Chart) { try { new ChartWriter(filepath).Write(song, exportOptions, out errorMessageList); //song.Save(filepath, exportOptions); } catch (System.Exception e) { Logger.LogException(e, "Error when exporting chart"); errorMessageList += e.Message; } } else if (exportOptions.format == ExportOptions.Format.Midi) { try { MidWriter.WriteToFile(filepath, song, exportOptions); } catch (System.Exception e) { Logger.LogException(e, "Error when exporting midi"); errorMessageList += e.Message; } } }) }; if (generateIniToggle.isOn) { tasks.Add(new LoadingTask("Generating Song.ini", () => { GenerateSongIni(Path.GetDirectoryName(filepath), song); })); } tasksManager.KickTasks(tasks); while (tasksManager.isRunningTask) { yield return(null); } Debug.Log("Total exporting time: " + (Time.realtimeSinceStartup - timer)); if (errorMessageList != string.Empty) { ChartEditor.Instance.errorManager.QueueErrorMessage("Encountered the following errors while exporting: " + Globals.LINE_ENDING + errorMessageList); } }
public IEnumerator _ExportSong(string filepath) { LoadingTasksManager tasksManager = editor.services.loadingTasksManager; Song song = editor.currentSong;// new Song(editor.currentSong); float songLength = editor.currentSongLength; exportOptions.tickOffset = TickFunctions.TimeToDis(0, delayTime, exportOptions.targetResolution, 120); float timer = Time.realtimeSinceStartup; string errorMessageList = string.Empty; List <LoadingTask> tasks = new List <LoadingTask>() { new LoadingTask("Exporting " + exportOptions.format, () => { if (exportOptions.format == ExportOptions.Format.Chart) { try { ChartWriter.ErrorReport errorReport; Debug.Log("Exporting CHART file to " + filepath); new ChartWriter(filepath).Write(song, exportOptions, out errorReport); errorMessageList = errorReport.errorList.ToString(); } catch (System.Exception e) { Logger.LogException(e, "Error when exporting chart"); errorMessageList += e.Message; } } else if (exportOptions.format == ExportOptions.Format.Midi) { try { Debug.Log("Exporting MIDI file to " + filepath); MidWriter.WriteToFile(filepath, song, exportOptions); } catch (System.Exception e) { Logger.LogException(e, "Error when exporting midi"); errorMessageList += e.Message; } } }) }; if (generateIniToggle.isOn) { tasks.Add(new LoadingTask("Generating Song.ini", () => { GenerateSongIni(Path.GetDirectoryName(filepath), song, songLength); })); } tasksManager.KickTasks(tasks); while (tasksManager.isRunningTask) { yield return(null); } Debug.Log("Total exporting time: " + (Time.realtimeSinceStartup - timer)); if (exportOptions.format == ExportOptions.Format.Midi) { bool hasErrors; SongValidate.ValidationParameters validateParams = new SongValidate.ValidationParameters() { songLength = editor.currentSongLength, checkMidiIssues = true, }; string validationErrors = SongValidate.GenerateReport(SongValidate.ValidationOptions.CloneHero, editor.currentSong, validateParams, out hasErrors); if (hasErrors) { errorMessageList += '\n'; errorMessageList += validationErrors; } } if (errorMessageList != string.Empty) { Disable(); ChartEditor.Instance.errorManager.QueueErrorMessage("Encountered the following errors while exporting: " + Globals.LINE_ENDING + errorMessageList); } }