public void UserCheckForUpdates() { ApplicationUpdateManager updateManager = services.updateManager; updateManager.CheckForUpdates(OnUserCheckForUpdatesComplete); LoadingTask waitForUpdateCheckTask = new LoadingTask("Checking for updates...", () => { while (updateManager.UpdateCheckInProgress) { ; } }); List <LoadingTask> tasks = new List <LoadingTask>() { waitForUpdateCheckTask }; LoadingTasksManager tasksManager = services.loadingTasksManager; tasksManager.KickTasks(tasks); }
IEnumerator SetAudio() { LoadingTasksManager tasksManager = editor.services.loadingTasksManager; List <LoadingTask> tasks = new List <LoadingTask>() { new LoadingTask("Loading audio", () => { while (editor.currentSongAudio.isAudioLoading) { ; } }) }; tasksManager.KickTasks(tasks); while (tasksManager.isRunningTask) { yield return(null); } setAudioTextLabels(); }
IEnumerator ExportCHPackage(string destFolderPath, Song song, ExportOptions exportOptions) { Song newSong = song;//new Song(song); LoadingTasksManager tasksManager = editor.services.loadingTasksManager; float timer = Time.realtimeSinceStartup; string errorMessageList = string.Empty; destFolderPath = destFolderPath.Replace('\\', '/'); if (!destFolderPath.EndsWith("/")) { destFolderPath += '/'; } if (!Directory.Exists(destFolderPath)) { Directory.CreateDirectory(destFolderPath); } List <LoadingTask> tasks = new List <LoadingTask>() { new LoadingTask("Re-encoding audio to .ogg format", () => { ExportSongAudioOgg(destFolderPath, newSong); }), new LoadingTask("Exporting chart", () => { string chartOutputFile = destFolderPath + "notes.chart"; // Set audio location after audio files have already been created as set won't won't if the files don't exist foreach (Song.AudioInstrument audio in EnumX <Song.AudioInstrument> .Values) { if (song.GetAudioLocation(audio) != string.Empty) { string audioFilename = GetCHOggFilename(audio); string audioPath = destFolderPath + audioFilename; newSong.SetAudioLocation(audio, audioPath); } } new ChartWriter(chartOutputFile).Write(newSong, exportOptions, out errorMessageList); GenerateSongIni(destFolderPath, newSong); }), }; 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); 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 _Load(string currentFileName, bool recordLastLoaded = true) { LoadingTasksManager tasksManager = services.loadingTasksManager; bool error = false; Song backup = currentSong; #if TIMING_DEBUG float totalLoadTime = Time.realtimeSinceStartup; #endif bool mid = false; Song newSong = null; MidReader.CallbackState midiCallbackState = MidReader.CallbackState.None; List <LoadingTask> tasks = new List <LoadingTask>() { new LoadingTask("Loading file", () => { // Wait for saving to complete just in case while (currentSong.isSaving) { } if (errorManager.HasErrorToDisplay()) { error = true; return; } mid = System.IO.Path.GetExtension(currentFileName) == ".mid"; try { if (mid) { newSong = MidReader.ReadMidi(currentFileName, ref midiCallbackState); } else { newSong = ChartReader.ReadChart(currentFileName); } } catch (Exception e) { currentSong = backup; if (mid) { errorManager.QueueErrorMessage(Logger.LogException(e, "Failed to open mid file")); } else { errorManager.QueueErrorMessage(Logger.LogException(e, "Failed to open chart file")); } error = true; } }), new LoadingTask("Loading audio", () => { if (error) { return; } // Free the previous audio clips FreeAudio(); newSong.LoadAllAudioClips(); }), }; tasksManager.KickTasks(tasks); while (tasksManager.isRunningTask) { while (midiCallbackState == MidReader.CallbackState.WaitingForExternalInformation) { // Halt main thread until message box is complete } yield return(null); } // Tasks have finished if (error) { yield break; // Immediate exit } isDirty = false; if (mid) { currentFileName = string.Empty; isDirty = true; Debug.Log("Loaded mid file"); } if (recordLastLoaded && currentFileName != string.Empty && !mid) { lastLoadedFile = System.IO.Path.GetFullPath(currentFileName); } else { lastLoadedFile = string.Empty; } currentSong = newSong; LoadSong(currentSong); #if TIMING_DEBUG Debug.Log("Total load time: " + (Time.realtimeSinceStartup - totalLoadTime)); #endif }
IEnumerator ExportCHPackage(string destFolderPath, Song song, float songLengthSeconds, ExportOptions exportOptions) { Song newSong = new Song(song); LoadingTasksManager tasksManager = editor.services.loadingTasksManager; float timer = Time.realtimeSinceStartup; string errorMessageList = string.Empty; Directory.CreateDirectory(destFolderPath); List <LoadingTask> tasks = new List <LoadingTask>(); // Determine how many actions ahead of time so that we can display progress of how many songs it has re-encoded, eg "(1/2)" List <Action> songEncodeActions = new List <Action>(); foreach (Song.AudioInstrument audio in EnumX <Song.AudioInstrument> .Values) { string audioLocation = song.GetAudioLocation(audio); if (audioLocation == string.Empty) { continue; } if (!File.Exists(audioLocation)) { Debug.LogErrorFormat("Unable to find audio file in location {0}", audioLocation); continue; } string newAudioName = GetCHOggFilename(audio); if (string.IsNullOrEmpty(newAudioName)) { Debug.LogErrorFormat("Audio instrument {0} not set up in ch name dict. Skipping.", audio.ToString()); continue; } string outputFile = Path.Combine(destFolderPath, newAudioName); songEncodeActions.Add(() => { Debug.LogFormat("Converting ogg from {0} to {1}", audioLocation, outputFile); AudioManager.ConvertToOgg(audioLocation, outputFile); }); } for (int i = 0; i < songEncodeActions.Count; ++i) { tasks.Add(new LoadingTask(string.Format("Re-encoding audio to .ogg format ({0}/{1})", i + 1, songEncodeActions.Count), songEncodeActions[i])); } tasks.Add(new LoadingTask("Exporting chart", () => { string chartOutputFile = Path.Combine(destFolderPath, "notes.chart"); // Set audio location after audio files have already been created as set won't won't if the files don't exist foreach (Song.AudioInstrument audio in EnumX <Song.AudioInstrument> .Values) { if (song.GetAudioLocation(audio) != string.Empty) { string audioFilename = GetCHOggFilename(audio); string audioPath = Path.Combine(destFolderPath, audioFilename); newSong.SetAudioLocation(audio, audioPath); } } ChartWriter.ErrorReport errorReport; new ChartWriter(chartOutputFile).Write(newSong, exportOptions, out errorReport); GenerateSongIni(destFolderPath, newSong, songLengthSeconds, true); errorMessageList = errorReport.errorList.ToString(); })); 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); } }
public IEnumerator _Load(string currentFileName, bool recordLastLoaded = true) { LoadingTasksManager tasksManager = services.loadingTasksManager; bool error = false; Song backup = currentSong; #if TIMING_DEBUG float totalLoadTime = Time.realtimeSinceStartup; #endif bool mid = false; Song newSong = null; MidReader.CallbackState midiCallbackState = MidReader.CallbackState.None; List <LoadingTask> tasks = new List <LoadingTask>() { new LoadingTask("Loading file", () => { // Wait for saving to complete just in case while (isSaving) { } if (errorManager.HasErrorToDisplay()) { error = true; return; } mid = System.IO.Path.GetExtension(currentFileName) == ".mid"; try { if (mid) { newSong = MidReader.ReadMidi(currentFileName, ref midiCallbackState); } else { newSong = ChartReader.ReadChart(currentFileName); } } catch (Exception e) { currentSong = backup; if (mid) { errorManager.QueueErrorMessage(Logger.LogException(e, "Failed to open mid file")); } else { errorManager.QueueErrorMessage(Logger.LogException(e, "Failed to open chart file")); } error = true; } try { string directory = System.IO.Path.GetDirectoryName(currentFileName); string iniPath = System.IO.Path.Combine(directory, "song.ini"); if (newSong != null && System.IO.File.Exists(iniPath)) { try { newSong.iniProperties.Open(iniPath); newSong.iniProperties = SongIniFunctions.FixupSongIniWhitespace(newSong.iniProperties); } catch (Exception e) { errorManager.QueueErrorMessage(Logger.LogException(e, "Failed to parse song.ini")); } finally { newSong.iniProperties.Close(); } } } catch (Exception e) { // TODO } }), new LoadingTask("Loading audio", () => { if (error) { return; } // Free the previous audio clips currentSongAudio.FreeAudioStreams(); currentSongAudio.LoadAllAudioClips(newSong); }), }; tasksManager.KickTasks(tasks); while (tasksManager.isRunningTask) { while (midiCallbackState == MidReader.CallbackState.WaitingForExternalInformation) { // Halt main thread until message box is complete } yield return(null); } // Tasks have finished if (error) { yield break; // Immediate exit } isDirty = false; if (mid) { currentFileName = string.Empty; isDirty = true; Debug.Log("Loaded mid file"); } if (recordLastLoaded && currentFileName != string.Empty && !mid) { lastLoadedFile = System.IO.Path.GetFullPath(currentFileName); } else { lastLoadedFile = string.Empty; } currentSong = newSong; sessionFlags &= ~ChartEditorSessionFlags.CurrentChartSavedInProprietyFormat; LoadSong(currentSong); #if TIMING_DEBUG Debug.Log("Total load time: " + (Time.realtimeSinceStartup - totalLoadTime)); #endif }