public void NewFile() { DeleteTargets(); notes = new List <GridTarget>(); notesTimeline = new List <TimelineTarget>(); string dirpath = Application.persistentDataPath; //create the new song desc songDesc = new SongDesc(); //locate and copy ogg file to temp folder (used to save the project later) var audioFiles = StandaloneFileBrowser.OpenFilePanel("Import .ogg file", System.Environment.GetFolderPath(Environment.SpecialFolder.MyMusic), "ogg", false); if (audioFiles.Length > 0) { FileInfo oggFile = new FileInfo(audioFiles[0]); if (!System.IO.Directory.Exists(dirpath + "\\temp\\")) { System.IO.Directory.CreateDirectory(dirpath + "\\temp\\", securityRules); } else { DirectoryInfo direct = new DirectoryInfo(dirpath + "\\temp\\"); direct.Delete(true); System.IO.Directory.CreateDirectory(dirpath + "\\temp\\", securityRules); } oggFile.CopyTo(dirpath + "\\temp\\" + oggFile.Name, true); //load ogg into audio clip if (audioFiles.Length > 0) { StartCoroutine(GetAudioClip(audioFiles[0])); } else { Debug.Log("ogg not found"); } } else { Application.Quit(); } }
public void Import() { var descFiles = Directory.GetFiles(Environment.CurrentDirectory, "song.desc"); if (descFiles.Length > 0) { string json = File.ReadAllText(descFiles[0]); songDesc = JsonUtility.FromJson <SongDesc>(json); SetOffset(songDesc.offset); SetSongID(songDesc.songID); SetSongTitle(songDesc.title); SetSongArtist(songDesc.artist); SetSongEndEvent(songDesc.songEndEvent.Replace("event:/song_end/song_end_", string.Empty)); SetSongPreRoll(songDesc.prerollSeconds); SetSongAuthor(songDesc.author); } else { songDesc = new SongDesc(); } var cueFiles = Directory.GetFiles(Environment.CurrentDirectory, "*.cues"); if (cueFiles.Length > 0) { string json = File.ReadAllText(cueFiles[0]); json = json.Replace("cues", "Items"); Cue[] cues = JsonHelper.FromJson <Cue>(json); foreach (Cue cue in cues) { AddTarget(cue); } } var audioFiles = Directory.GetFiles(Environment.CurrentDirectory, "*.ogg"); if (audioFiles.Length > 0) { StartCoroutine(GetAudioClip(audioFiles[0])); } }
public bool LoadAudicaFile(bool loadRecent = false, string filePath = null) { inTimingMode = false; SetOffset(0); if (audicaLoaded) { Export(); } if (loadRecent) { audicaFile = null; DeleteAllTargets(); audicaFile = AudicaHandler.LoadAudicaFile(PlayerPrefs.GetString("recentFile", null)); if (audicaFile == null) { return(false); } } else if (filePath != null) { audicaFile = null; DeleteAllTargets(); audicaFile = AudicaHandler.LoadAudicaFile(filePath); PlayerPrefs.SetString("recentFile", audicaFile.filepath); } else { string[] paths = StandaloneFileBrowser.OpenFilePanel("Audica File (Not OST)", Path.Combine(Application.persistentDataPath), "audica", false); if (paths.Length == 0) { return(false); } audicaFile = null; DeleteAllTargets(); audicaFile = AudicaHandler.LoadAudicaFile(paths[0]); PlayerPrefs.SetString("recentFile", paths[0]); } desc = audicaFile.desc; // Get song BPM if (audicaFile.song_mid != null) { float oneMinuteInMicroseconds = 60000000f; var midiBpm = -1; foreach (var tempo in audicaFile.song_mid.GetTempoMap().Tempo) { // TODO: Multi-bpm support :( // Debug.Log($"FOUND TEMPO EVENT: {tempo}, BPM: {tempo.Value.BeatsPerMinute}"); midiBpm = (int)Math.Round(oneMinuteInMicroseconds / tempo.Value.MicrosecondsPerQuarterNote); } if (midiBpm != desc.tempo && midiBpm != -1) { // TODO: in-scene dialog box :/ //if (EditorUtility.DisplayDialog("BPM mismatch", //"Detected different BPM values in midi and song.desc. NotReaper does not currently support multi-bpm tracks.", // $"Use midi ({midiBpm})", $"Use song.desc ({desc.tempo})")) { desc.tempo = midiBpm; //} } } //Update our discord presence nrDiscordPresence.UpdatePresenceSongName(desc.title); //Loads all the sounds. StartCoroutine(GetAudioClip($"file://{Application.dataPath}/.cache/{audicaFile.desc.cachedMainSong}.ogg")); StartCoroutine(LoadLeftSustain($"file://{Application.dataPath}/.cache/{audicaFile.desc.cachedSustainSongLeft}.ogg")); StartCoroutine(LoadRightSustain($"file://{Application.dataPath}/.cache/{audicaFile.desc.cachedSustainSongRight}.ogg")); //foreach (Cue cue in audicaFile.diffs.expert.cues) { //AddTarget(cue); //} //Difficulty manager loads stuff now audicaLoaded = true; difficultyManager.LoadHighestDifficulty(); //Disable timing window buttons so users don't mess stuff up. applyButtonTiming.interactable = false; generateAudicaButton.interactable = false; loadAudioFileTiming.interactable = false; //Loaded successfully NotificationShower.AddNotifToQueue(new NRNotification("Map loaded successfully!")); NotificationShower.AddNotifToQueue(new NRNotification("Hold F1 to view shortcuts")); return(true); }
public ReviewContainer() { this.songDesc = Timeline.desc; }
public ReviewContainer(SongDesc songDesc) { this.songDesc = songDesc; }
public void LoadFromFile(string edicaSave) { DeleteTargets(); if (edicaSave.Length > 0) { PlayerPrefs.SetString("previousSave", edicaSave); //move zip to temp folder string dirpath = Application.persistentDataPath; if (!System.IO.Directory.Exists(dirpath + "\\temp\\")) { System.IO.Directory.CreateDirectory(dirpath + "\\temp\\", securityRules); } else { DirectoryInfo direct = new DirectoryInfo(dirpath + "\\temp\\"); direct.Delete(true); System.IO.Directory.CreateDirectory(dirpath + "\\temp\\", securityRules); } //unzip save into temp ZipFile.ExtractToDirectory(edicaSave, dirpath + "\\temp\\"); //load desc from temp var descFiles = Directory.GetFiles(dirpath + "\\temp\\", "song.desc"); if (descFiles.Length > 0) { string json = File.ReadAllText(dirpath + "\\temp\\song.desc"); songDesc = JsonUtility.FromJson <SongDesc>(json); SetOffset(songDesc.offset); SetSongID(songDesc.songID); SetSongTitle(songDesc.title); SetSongArtist(songDesc.artist); SetSongEndEvent(songDesc.songEndEvent.Replace("event:/song_end/song_end_", string.Empty)); SetSongPreRoll(songDesc.prerollSeconds); SetSongAuthor(songDesc.author); } else { Debug.Log("desc not found"); songDesc = new SongDesc(); } //load cues from temp //var cueFile = Directory.GetFiles(dirpath + "\\temp\\", DifficultySelection_s.Value + ".cues"); var cueFiles = Directory.GetFiles(dirpath + "\\temp\\", "*.cues"); if (cueFiles.Length > 0) { //figure out if it has difficulties (new edica file) bool isDifficultyNamed = false; string difficulty = ""; foreach (var file in cueFiles) { if (file.Contains("expert.cues")) { isDifficultyNamed = true; difficulty = "expert"; } else if (file.Contains("advanced.cues")) { isDifficultyNamed = true; difficulty = "advanced"; } else if (file.Contains("moderate.cues")) { isDifficultyNamed = true; difficulty = "moderate"; } else if (file.Contains("beginner.cues")) { isDifficultyNamed = true; difficulty = "beginner"; } } if (isDifficultyNamed) { DifficultySelection_s.Value = difficulty; DifficultySelection_s.selection.value = (int)DifficultySelection.Options.Parse(typeof(DifficultySelection.Options), difficulty); //load .cues (delete first because changing difficulty creates targets) DeleteTargets(); var cueFile = Directory.GetFiles(dirpath + "\\temp\\", difficulty + ".cues"); string json = File.ReadAllText(cueFile[0]); json = json.Replace("cues", "Items"); Cue[] cues = JsonHelper.FromJson <Cue>(json); foreach (Cue cue in cues) { AddTarget(cue); } } else //old edica format. Shove it into expert { string json = File.ReadAllText(cueFiles[0]); json = json.Replace("cues", "Items"); Cue[] cues = JsonHelper.FromJson <Cue>(json); foreach (Cue cue in cues) { AddTarget(cue); } } } else { Debug.Log("cues not found"); NewFile(); } //load ogg into audio clip var audioFiles = Directory.GetFiles(dirpath + "\\temp\\", "*.ogg"); if (audioFiles.Length > 0) { StartCoroutine(GetAudioClip(audioFiles[0])); } else { Debug.Log("ogg not found"); } } else { NewFile(); } }
public static string Generate(string oggPath, string songID, string songName, string artist, double bpm, string songEndEvent, string author, int offset) { HandleCache.CheckSaveFolderValid(); var workFolder = Path.Combine(Application.streamingAssetsPath, "Ogg2Audica"); string audicaTemplate = Path.Combine(workFolder, ".AudicaTemplate/"); Encoding encoding = Encoding.GetEncoding("UTF-8"); //We need to modify the BPM of the song.mid contained in the template audica to match whatever this is. File.Delete(Path.Combine(workFolder, "song.mid")); MidiFile songMidi = MidiFile.Read(Path.Combine(workFolder, "songtemplate.mid")); float oneMinuteInMicroseconds = 60000000f; songMidi.ReplaceTempoMap(TempoMap.Create(new Tempo((long)(oneMinuteInMicroseconds / bpm)))); songMidi.Write(Path.Combine(workFolder, "song.mid"), true, MidiFileFormat.MultiTrack); //Generates the mogg into song.mogg, which is moved to the .AudicaTemplate File.Delete(Path.Combine(workFolder, "song.mogg")); Process ogg2mogg = new Process(); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; startInfo.FileName = Path.Combine(workFolder, "ogg2mogg.exe"); string args = $"\"{oggPath}\" \"{workFolder}/song.mogg\""; startInfo.Arguments = args; startInfo.UseShellExecute = false; ogg2mogg.StartInfo = startInfo; ogg2mogg.Start(); ogg2mogg.WaitForExit(); //Make the song.desc file; File.Delete(Path.Combine(workFolder, "song.desc")); SongDesc songDesc = JsonUtility.FromJson <SongDesc>(File.ReadAllText(Path.Combine(workFolder, "songtemplate.desc"))); songDesc.songID = songID; songDesc.title = songName; songDesc.artist = artist; songDesc.tempo = (float)bpm; songDesc.songEndEvent = songEndEvent; songDesc.author = author; songDesc.offset = offset; File.WriteAllText(Path.Combine(workFolder, "song.desc"), JsonUtility.ToJson(songDesc, true)); //Create the actual audica file and save it to the /saves/ folder using (ZipArchive archive = ZipArchive.Create()) { archive.AddAllFromDirectory(audicaTemplate); archive.AddEntry("song.desc", Path.Combine(workFolder, "song.desc")); archive.AddEntry("song.mid", Path.Combine(workFolder, "song.mid")); archive.AddEntry("song.mogg", Path.Combine(workFolder, "song.mogg")); archive.SaveTo(Path.Combine(Application.dataPath, "saves", songID + ".audica"), SharpCompress.Common.CompressionType.None); } return(Path.Combine(Application.dataPath, "saves", songID + ".audica")); /* * * HandleCache.CheckSaveFolderValid(); * * System.Diagnostics.Process myProcess = new System.Diagnostics.Process(); * ProcessStartInfo startInfo = new ProcessStartInfo(); * startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; * startInfo.FileName = Path.Combine(ogg2AudicaFolder, "Ogg2Audica.exe"); * * startInfo.Arguments = System.String.Format("\"{0}\" \"{1}\" \"{2}\" \"{3}\" \"{4}\" \"{5}\" \"{6}\" \"{7}\"", oggPath, songID, songName, artist, bpm, songEndEvent, mapper, offset); * startInfo.UseShellExecute = true; * startInfo.WorkingDirectory = ogg2AudicaFolder; * * myProcess.StartInfo = startInfo; * * myProcess.Start(); * * myProcess.WaitForExit(); * * File.Move(Path.Combine(ogg2AudicaFolder, "out.audica"), Path.Combine(Application.dataPath, "saves", songID + ".audica")); * * * return Path.Combine(Application.dataPath, "saves", songID + ".audica"); */ }
public static string Generate(string oggPath, float moggSongVol, string songID, string songName, string artist, double bpm, string songEndEvent, string author, int offset, string midiPath, string artPath) { HandleCache.CheckSaveFolderValid(); var workFolder = Path.Combine(Application.streamingAssetsPath, "Ogg2Audica"); string audicaTemplate = Path.Combine(workFolder, "AudicaTemplate/"); Encoding encoding = Encoding.GetEncoding("UTF-8"); //Album art File.Delete(Path.Combine(workFolder, "song.png")); if (!string.IsNullOrEmpty(artPath)) { UnityEngine.Debug.Log("Album art found"); File.Copy(artPath, Path.Combine(workFolder, "song.png")); } //We need to modify the BPM of the song.mid contained in the template audica to match whatever this is. File.Delete(Path.Combine(workFolder, "song.mid")); File.Copy(midiPath, Path.Combine(workFolder, "song.mid")); //Generates the mogg into song.mogg, which is moved to the AudicaTemplate File.Delete(Path.Combine(workFolder, "song.mogg")); Process ogg2mogg = new Process(); ProcessStartInfo startInfo = new ProcessStartInfo(); startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; startInfo.FileName = Path.Combine(workFolder, "ogg2mogg.exe"); if ((Application.platform == RuntimePlatform.LinuxEditor) || (Application.platform == RuntimePlatform.LinuxPlayer)) { startInfo.FileName = Path.Combine(workFolder, "ogg2mogg"); } if ((Application.platform == RuntimePlatform.OSXEditor) || (Application.platform == RuntimePlatform.OSXPlayer)) { startInfo.FileName = Path.Combine(workFolder, "ogg2moggOSX"); } string args = $"\"{oggPath}\" \"{workFolder}/song.mogg\""; startInfo.Arguments = args; startInfo.UseShellExecute = false; ogg2mogg.StartInfo = startInfo; ogg2mogg.Start(); ogg2mogg.WaitForExit(); //Set the song.moggsong volume var moggpath = Path.Combine(workFolder, "song.moggsong"); var moggsongTemplate = Path.Combine(workFolder, "MoggsongTemplate", "song.moggsong"); File.Delete(moggpath); File.Copy(moggsongTemplate, moggpath); File.WriteAllText(moggpath, File.ReadAllText(moggpath).Replace("-5", moggSongVol.ToString("n2"))); //Make the song.desc file; File.Delete(Path.Combine(workFolder, "song.desc")); SongDesc songDesc = JsonUtility.FromJson <SongDesc>(File.ReadAllText(Path.Combine(workFolder, "songtemplate.desc"))); songDesc.songID = songID; songDesc.title = songName; songDesc.artist = artist; if (!string.IsNullOrEmpty(artPath)) { songDesc.albumArt = "song.png"; } songDesc.tempo = (float)bpm; songDesc.songEndEvent = songEndEvent; songDesc.author = author; songDesc.offset = offset; File.WriteAllText(Path.Combine(workFolder, "song.desc"), Newtonsoft.Json.JsonConvert.SerializeObject(songDesc, Newtonsoft.Json.Formatting.Indented)); /*File.Delete(Path.Combine(workFolder, "modifiers.json")); * ModifierList modifierList = new ModifierList(); * modifierList.modifiers = ModifierHandler.instance.modifiers; * File.WriteAllText(Path.Combine(workFolder, "modifiers.json"), JsonUtility.ToJson(modifierList, true)); */ File.Create(Path.Combine(workFolder, "modifiers.json")); //Create the actual audica file and save it to the /saves/ folder using (ZipArchive archive = ZipArchive.Create()) { archive.AddAllFromDirectory(audicaTemplate); archive.AddEntry("song.desc", Path.Combine(workFolder, "song.desc")); archive.AddEntry("song.mid", Path.Combine(workFolder, "song.mid")); archive.AddEntry("song.mogg", Path.Combine(workFolder, "song.mogg")); archive.AddEntry("song.moggsong", Path.Combine(workFolder, "song.moggsong")); if (!string.IsNullOrEmpty(artPath)) { archive.AddEntry("song.png", Path.Combine(workFolder, "song.png")); } archive.SaveTo(Path.Combine(Application.dataPath, @"../", "saves", songID + ".audica"), SharpCompress.Common.CompressionType.None); } return(Path.Combine(Application.dataPath, @"../", "saves", songID + ".audica")); /* * * HandleCache.CheckSaveFolderValid(); 59.6, 57.8 * * System.Diagnostics.Process myProcess = new System.Diagnostics.Process(); * ProcessStartInfo startInfo = new ProcessStartInfo(); * startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal; * startInfo.FileName = Path.Combine(ogg2AudicaFolder, "Ogg2Audica.exe"); * * startInfo.Arguments = System.String.Format("\"{0}\" \"{1}\" \"{2}\" \"{3}\" \"{4}\" \"{5}\" \"{6}\" \"{7}\"", oggPath, songID, songName, artist, bpm, songEndEvent, mapper, offset); * startInfo.UseShellExecute = true; * startInfo.WorkingDirectory = ogg2AudicaFolder; * * myProcess.StartInfo = startInfo; * * myProcess.Start(); * * myProcess.WaitForExit(); * * File.Move(Path.Combine(ogg2AudicaFolder, "out.audica"), Path.Combine(Application.dataPath, "saves", songID + ".audica")); * * * return Path.Combine(Application.dataPath, "saves", songID + ".audica"); */ }
public bool LoadAudicaFile(bool loadRecent = false, string filePath = null) { inTimingMode = false; if (audicaLoaded) { Export(); } DeleteAllTargets(); audicaFile = null; if (loadRecent) { audicaFile = AudicaHandler.LoadAudicaFile(PlayerPrefs.GetString("recentFile", null)); if (audicaFile == null) { return(false); } } else if (filePath != null) { audicaFile = AudicaHandler.LoadAudicaFile(filePath); PlayerPrefs.SetString("recentFile", audicaFile.filepath); } else { string[] paths = StandaloneFileBrowser.OpenFilePanel("Audica File (Not OST)", Path.Combine(Application.persistentDataPath), "audica", false); if (paths.Length == 0) { return(false); } audicaFile = AudicaHandler.LoadAudicaFile(paths[0]); PlayerPrefs.SetString("recentFile", paths[0]); } //SetOffset(0); desc = audicaFile.desc; //Update our discord presence nrDiscordPresence.UpdatePresenceSongName(desc.title); //Loads all the sounds. StartCoroutine(GetAudioClip($"file://{Application.dataPath}/.cache/{audicaFile.desc.cachedMainSong}.ogg")); StartCoroutine(LoadLeftSustain($"file://{Application.dataPath}/.cache/{audicaFile.desc.cachedSustainSongLeft}.ogg")); StartCoroutine(LoadRightSustain($"file://{Application.dataPath}/.cache/{audicaFile.desc.cachedSustainSongRight}.ogg")); //foreach (Cue cue in audicaFile.diffs.expert.cues) { //AddTarget(cue); //} //Difficulty manager loads stuff now audicaLoaded = true; difficultyManager.LoadHighestDifficulty(); //Disable timing window buttons so users don't mess stuff up. applyButtonTiming.interactable = false; generateAudicaButton.interactable = false; loadAudioFileTiming.interactable = false; //Loaded successfully NotificationShower.AddNotifToQueue(new NRNotification("Map loaded successfully!")); return(true); }