private void Start() { Conductor.OnBeat += _OnBeat; if (chartReaderObj != null) { chartReader = chartReaderObj.GetComponent <ChartReader>(); } else { Debug.LogError("Chart Reader Object Not Specified"); Application.Quit(); } if (chartFileLocation != "" && chartFileLocation.IndexOf(".txt") > 0) { if (chart == null) { Debug.LogError("Chart list null"); } if (chartReader == null) { Debug.LogError("Chart Reader component is null"); } chart = chartReader.ReadChart(chartFileLocation); } }
private void ScanForSongsRecursively(object folder) { List <SongInfo> list = new List <SongInfo>(); string[] chartFiles = Directory.GetFiles(dir, "*.chart", SearchOption.AllDirectories); string[] midFiles = Directory.GetFiles(dir, "*.mid", SearchOption.AllDirectories); string[] combinedFiles = chartFiles.Concat(midFiles).ToArray(); foreach (string s in combinedFiles) { switch (s.Substring(s.Length - 1, 1)) { case "t": try { ChartReader testReader = new ChartReader(); Song _testCurrentChart = new Song(); _testCurrentChart = testReader.ReadChartFile(s); list.Add(CreateSongInfo(s, Song.ChartType.chart)); } catch (Exception e) { } break; case "d": try { SongMID midFile = MidReader.ReadMidi(s, false); ChartWriter.WriteChart(midFile, dir + "/notes.chart", false); ChartReader testReader = new ChartReader(); Song _testCurrentChart = new Song(); _testCurrentChart = testReader.ReadChartFile(@dir + "/notes.chart"); File.Delete(@dir + "/notes.chart"); list.Add(CreateSongInfo(s, Song.ChartType.mid)); } catch (Exception e) { } break; } } lock (lockObject) { songs = list; } }
private IEnumerator SendRequest(string url) { using (UnityWebRequest request = UnityWebRequest.Get(url)) { yield return(request.SendWebRequest()); // entire file is returned via downloadHandler ChartReader chartReader = new ChartReader(); Chart = chartReader.ReadChartFile(request.downloadHandler.text); print(request.downloadHandler.text); // or //byte[] fileContents = request.downloadHandler.data; // do whatever you need to do with the file contents } }
public void StartLevel(Level lev, Difficulty diff) { _level = lev; _difficulty = diff; Init(); ChartReader chartReader = GetComponent <ChartReader>(); chart = chartReader.ReadChart(_level.chartFile, _speed, diff); List <Note> thisChartNotes = chart.Notes[diff]; _totalNumberNotes = thisChartNotes.Count; foreach (AudioClip clip in _level.musicFiles) { AudioSource s = gameObject.AddComponent <AudioSource>(); s.clip = clip; s.Play(); songAudioSources.Add(s); } _isRunning = true; }
IEnumerator ReadPhase2() { string pathaux = Application.streamingAssetsPath + Path; string[] filedata = null; if (pathaux.Contains("://")) { WWW www = new WWW(pathaux); yield return(www); //filedata = www.text; //filedata = www.text.Split('\n'); //C# filedata = www.text.Split( new [] { '\r', '\n' }); //Debug.Log(pathaux + " " + www.text); } else { filedata = IO.ReadFile(pathaux); } ChartReader chartReader = new ChartReader(); Chart = chartReader.ReadChartFileFromData(filedata); currentDifficulty = RetrieveDifficulty(); SpawnNotes(Chart.GetNotes(currentDifficulty)); SpawnStarPower(Chart.GetStarPower(currentDifficulty)); notelist = Chart.GetNotes(currentDifficulty); //SpawnSections(Chart.Sections); SpawnSynchTracks(Chart.SynchTracks); StartSong(); }
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 }
public IEnumerator _Load(string currentFileName, bool recordLastLoaded = true) { bool error = false; Song backup = currentSong; #if TIMING_DEBUG float totalLoadTime = 0; #endif // Start loading animation Globals.applicationMode = Globals.ApplicationMode.Loading; loadingScreen.FadeIn(); yield return(null); // Wait for saving to complete just in case while (currentSong.isSaving) { yield return(null); } if (SaveErrorCheck()) { yield break; } #if TIMING_DEBUG totalLoadTime = Time.realtimeSinceStartup; #endif bool mid = false; #if TIMING_DEBUG float time = Time.realtimeSinceStartup; #endif // Load the actual file loadingScreen.loadingInformation.text = "Loading file"; yield return(null); Song newSong = null; MidReader.CallbackState midiCallbackState = MidReader.CallbackState.None; System.Threading.Thread songLoadThread = new System.Threading.Thread(() => { 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) { ErrorMessage.errorMessage = Logger.LogException(e, "Failed to open mid file"); } else { ErrorMessage.errorMessage = Logger.LogException(e, "Failed to open chart file"); } error = true; } }); songLoadThread.Priority = System.Threading.ThreadPriority.Highest; songLoadThread.Start(); while (songLoadThread.ThreadState == System.Threading.ThreadState.Running) { while (midiCallbackState == MidReader.CallbackState.WaitingForExternalInformation) { // Halt thread until message box is complete } yield return(null); } if (error) { loadingScreen.FadeOut(); errorMenu.gameObject.SetActive(true); yield break; } #if TIMING_DEBUG Debug.Log("Chart file load time: " + (Time.realtimeSinceStartup - time)); time = Time.realtimeSinceStartup; #endif // Load the audio clips loadingScreen.loadingInformation.text = "Loading audio"; yield return(null); // Free the previous audio clips FreeAudio(); newSong.LoadAllAudioClips(); while (newSong.isAudioLoading) { yield return(null); } #if TIMING_DEBUG Debug.Log("All audio files load time: " + (Time.realtimeSinceStartup - time)); #endif yield return(null); isDirty = false; #if TIMING_DEBUG Debug.Log("File load time: " + (Time.realtimeSinceStartup - totalLoadTime)); #endif // Wait for audio to fully load while (newSong.isAudioLoading) { yield return(null); } 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 // Stop loading animation Globals.applicationMode = Globals.ApplicationMode.Editor; loadingScreen.FadeOut(); loadingScreen.loadingInformation.text = "Complete!"; }
private SongInfo CreateSongInfo(string s, Song.ChartType type) { SongInfo temp = new SongInfo(); string path = Path.GetDirectoryName(s); string[] songINIFile = Directory.GetFiles(path, "*.ini", SearchOption.AllDirectories); if (songINIFile.Length > 0 && File.Exists(path + "//song.ini")) { foreach (string line in File.ReadAllLines(path + "//song.ini")) { if (line.Contains("artist ") || line.Contains("artist=")) { string spaceRemove = line.Replace("= ", "=").Replace(" =", "="); temp.Artist = spaceRemove.Substring(7); } if (line.Contains("name ") || line.Contains("name=")) { string spaceRemove = line.Replace("= ", "=").Replace(" =", "="); temp.SongName = spaceRemove.Substring(5); } if (line.Contains("charter ") || line.Contains("charter=")) { string spaceRemove = line.Replace("= ", "=").Replace(" =", "="); temp.Charter = spaceRemove.Substring(8); } if (line.Contains("album ") || line.Contains("album=")) { string spaceRemove = line.Replace("= ", "=").Replace(" =", "="); temp.Album = spaceRemove.Substring(6); } if (line.Contains("delay ") || line.Contains("delay=")) { string spaceRemove = line.Replace("= ", "=").Replace(" =", "="); temp.offset = Math.Abs((long)Convert.ToUInt64(spaceRemove.Substring(6))); } if (line.Contains("preview_start_time ") || line.Contains("preview_start_time=")) { string spaceRemove = line.Replace("= ", "=").Replace(" =", "="); string value = spaceRemove.Substring(19); uint _time = 0; uint.TryParse(value, out _time); long time = Math.Abs(_time); temp.PreviewStartTime = time; } } temp.type = type; temp.fileLoction = s; return(temp); } else { ChartReader chartReader = new ChartReader(); Song _currentChart = new Song(); _currentChart = chartReader.ReadChartFile(s); temp.Artist = _currentChart.data.info.chartArtist; temp.SongName = _currentChart.data.info.chartName; temp.Charter = _currentChart.data.info.chartCharter; temp.PreviewStartTime = (long)_currentChart.data.info.previewStart; temp.type = type; temp.offset = (long)_currentChart.data.info.offset; temp.Album = "Album Unknown"; temp.fileLoction = s; } return(temp); }
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 }