Beispiel #1
0
        public static AudicaFile LoadAudicaFile(string path)
        {
            AudicaFile audicaFile = new AudicaFile();
            ZipFile    audicaZip  = ZipFile.Read(path);

            string appPath = Application.dataPath;
            bool   easy = false, standard = false, advanced = false, expert = false;


            HandleCache.CheckCacheFolderValid();
            HandleCache.ClearCueCache();

            //Figure out what files we need to extract by getting the song.desc.
            foreach (ZipEntry entry in audicaZip.Entries)
            {
                if (entry.FileName == "song.desc")
                {
                    MemoryStream ms = new MemoryStream();
                    entry.Extract(ms);
                    string tempDesc = Encoding.UTF8.GetString(ms.ToArray());

                    JsonUtility.FromJsonOverwrite(tempDesc, audicaFile.desc);


                    ms.Dispose();
                    continue;
                }

                //Extract the cues files.
                else if (entry.FileName == "expert.cues")
                {
                    entry.Extract($"{appPath}/.cache");
                    expert = true;
                }
                else if (entry.FileName == "advanced.cues")
                {
                    entry.Extract($"{appPath}/.cache");
                    advanced = true;
                }
                else if (entry.FileName == "moderate.cues")
                {
                    entry.Extract($"{appPath}/.cache");
                    standard = true;
                }
                else if (entry.FileName == "beginner.cues")
                {
                    entry.Extract($"{appPath}/.cache");
                    easy = true;
                }
            }

            //Now we fill the audicaFile var with all the things it needs.
            //Remember, all props in audicaFile.desc refer to either moggsong or the name of the mogg.
            //Real clips are stored in main audicaFile object.

            //Load the cues files.
            if (expert)
            {
                audicaFile.diffs.expert = JsonUtility.FromJson <CueFile>(File.ReadAllText($"{appPath}/.cache/expert.cues"));
            }
            if (advanced)
            {
                audicaFile.diffs.advanced = JsonUtility.FromJson <CueFile>(File.ReadAllText($"{appPath}/.cache/advanced.cues"));
            }
            if (standard)
            {
                audicaFile.diffs.moderate = JsonUtility.FromJson <CueFile>(File.ReadAllText($"{appPath}/.cache/moderate.cues"));
            }
            if (easy)
            {
                audicaFile.diffs.beginner = JsonUtility.FromJson <CueFile>(File.ReadAllText($"{appPath}/.cache/beginner.cues"));
            }

            MemoryStream temp = new MemoryStream();

            //Load the names of the moggs
            foreach (ZipEntry entry in audicaZip.Entries)
            {
                if (entry.FileName == audicaFile.desc.moggSong)
                {
                    entry.Extract(temp);
                    audicaFile.desc.moggMainSong = MoggSongParser.parse_metadata(Encoding.UTF8.GetString(temp.ToArray())) [0];
                }
                else if (entry.FileName == audicaFile.desc.sustainSongLeft)
                {
                    entry.Extract(temp);
                    audicaFile.desc.moggSustainSongLeft = MoggSongParser.parse_metadata(Encoding.UTF8.GetString(temp.ToArray())) [0];
                }
                else if (entry.FileName == audicaFile.desc.sustainSongRight)
                {
                    entry.Extract(temp);
                    audicaFile.desc.moggSustainSongRight = MoggSongParser.parse_metadata(Encoding.UTF8.GetString(temp.ToArray())) [0];
                }
                else if (entry.FileName == "song.mid")
                {
                    entry.Extract($"{appPath}/.cache", ExtractExistingFileAction.OverwriteSilently);
                    audicaFile.song_mid = MidiFile.Read($"{appPath}/.cache/song.mid");
                }

                temp.SetLength(0);
            }


            bool mainSongCached = false, sustainRightCached = false, sustainLeftCached = false;

            if (File.Exists($"{appPath}/.cache/{audicaFile.desc.cachedMainSong}.ogg"))
            {
                mainSongCached = true;
            }

            if (File.Exists($"{appPath}/.cache/{audicaFile.desc.cachedSustainSongRight}.ogg"))
            {
                sustainRightCached = true;
            }

            if (File.Exists($"{appPath}/.cache/{audicaFile.desc.cachedSustainSongLeft}.ogg"))
            {
                sustainLeftCached = true;
            }


            //If all the songs were already cached, skip this and go to the finish.
            if (mainSongCached && sustainRightCached && sustainLeftCached)
            {
                Debug.Log("Audio files were already cached and will be loaded.");
                goto Finish;
            }

            Debug.Log("Files not cached... Loading...");

            //If the files weren't cached, we now need to cache them manually then load them.
            MemoryStream tempMogg = new MemoryStream();

            foreach (ZipEntry entry in audicaZip.Entries)
            {
                if (!mainSongCached && entry.FileName == audicaFile.desc.moggMainSong)
                {
                    entry.Extract(tempMogg);
                    MoggToOgg(tempMogg.ToArray(), audicaFile.desc.cachedMainSong);
                }
                else if (!sustainRightCached && entry.FileName == audicaFile.desc.moggSustainSongRight)
                {
                    entry.Extract(tempMogg);
                    MoggToOgg(tempMogg.ToArray(), audicaFile.desc.cachedSustainSongRight);
                }
                else if (!sustainLeftCached && entry.FileName == audicaFile.desc.moggSustainSongLeft)
                {
                    entry.Extract(tempMogg);
                    MoggToOgg(tempMogg.ToArray(), audicaFile.desc.cachedSustainSongLeft);
                }

                tempMogg.SetLength(0);
            }

Finish:

            audicaFile.filepath = path;
            audicaZip.Dispose();

            return(audicaFile);
        }
        public static void ExportToAudicaFile(AudicaFile audicaFile)
        {
            if (!File.Exists(audicaFile.filepath))
            {
                Debug.Log("Save file is gone... :(");
                return;
            }

            Encoding encoding = Encoding.GetEncoding(437);

            using (var archive = ZipArchive.Open(audicaFile.filepath)) {
                HandleCache.CheckCacheFolderValid();
                HandleCache.CheckSaveFolderValid();

                bool expert = false, advanced = false, standard = false, easy = false;
                //Write the cues files to disk so we can add them to the audica file.
                if (audicaFile.diffs.expert.cues != null)
                {
                    File.WriteAllText($"{Application.dataPath}/.cache/expert-new.cues", CuesToJson(audicaFile.diffs.expert));
                    expert = true;
                }
                if (audicaFile.diffs.advanced.cues != null)
                {
                    File.WriteAllText($"{Application.dataPath}/.cache/advanced-new.cues", CuesToJson(audicaFile.diffs.advanced));
                    advanced = true;
                }
                if (audicaFile.diffs.moderate.cues != null)
                {
                    File.WriteAllText($"{Application.dataPath}/.cache/moderate-new.cues", CuesToJson(audicaFile.diffs.moderate));
                    standard = true;
                }
                if (audicaFile.diffs.beginner.cues != null)
                {
                    File.WriteAllText($"{Application.dataPath}/.cache/beginner-new.cues", CuesToJson(audicaFile.diffs.beginner));
                    easy = true;
                }

                File.WriteAllText($"{Application.dataPath}/.cache/song-new.desc", JsonUtility.ToJson(audicaFile.desc));

                var      workFolder = Path.Combine(Application.streamingAssetsPath, "Ogg2Audica");
                MidiFile songMidi   = new MidiFile(Path.Combine(workFolder, "songtemplate.mid"));

                MidiEventCollection events = new MidiEventCollection(0, (int)Constants.PulsesPerQuarterNote);
                foreach (var tempo in audicaFile.desc.tempoList)
                {
                    events.AddEvent(new TempoEvent((int)tempo.microsecondsPerQuarterNote, (long)tempo.time.tick), 0);
                    events.AddEvent(new TimeSignatureEvent((long)tempo.time.tick, (int)tempo.timeSignature.Numerator, (int)TimeSignature.GetMIDIDenominator(tempo.timeSignature.Denominator), 0, 8), 0);
                }

                events.PrepareForExport();
                MidiFile.Export(Path.Combine(workFolder, $"{Application.dataPath}/.cache/song.mid"), events);

                //Remove any files we'll be replacing
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    if (entry.ToString() == "expert.cues")
                    {
                        archive.RemoveEntry(entry);
                    }
                    else if (entry.ToString() == "song.desc")
                    {
                        archive.RemoveEntry(entry);
                    }
                    else if (entry.ToString() == "song.mid")
                    {
                        archive.RemoveEntry(entry);
                    }
                    else if (entry.ToString() == "advanced.cues")
                    {
                        archive.RemoveEntry(entry);
                    }
                    else if (entry.ToString() == "moderate.cues")
                    {
                        archive.RemoveEntry(entry);
                    }
                    else if (entry.ToString() == "beginner.cues")
                    {
                        archive.RemoveEntry(entry);
                    }
                }
                if (expert)
                {
                    archive.AddEntry("expert.cues", $"{Application.dataPath}/.cache/expert-new.cues");
                }
                if (advanced)
                {
                    archive.AddEntry("advanced.cues", $"{Application.dataPath}/.cache/advanced-new.cues");
                }
                if (standard)
                {
                    archive.AddEntry("moderate.cues", $"{Application.dataPath}/.cache/moderate-new.cues");
                }
                if (easy)
                {
                    archive.AddEntry("beginner.cues", $"{Application.dataPath}/.cache/beginner-new.cues");
                }

                archive.AddEntry("song.desc", $"{Application.dataPath}/.cache/song-new.desc");
                archive.AddEntry("song.mid", $"{Application.dataPath}/.cache/song.mid");
                archive.SaveTo(audicaFile.filepath + ".temp", SharpCompress.Common.CompressionType.None);
                archive.Dispose();
            }
            File.Delete(audicaFile.filepath);
            File.Move(audicaFile.filepath + ".temp", audicaFile.filepath);


            Debug.Log("Export finished.");
        }
Beispiel #3
0
        public static AudicaFile LoadAudicaFile(string path)
        {
            AudicaFile audicaFile = new AudicaFile();
            ZipFile    audicaZip  = ZipFile.Read(path);


            string appPath = Application.dataPath;
            bool   easy = false, standard = false, advanced = false, expert = false, modifiers = false;


            HandleCache.CheckCacheFolderValid();
            HandleCache.ClearCueCache();
            //Figure out what files we need to extract by getting the song.desc.
            foreach (ZipEntry entry in audicaZip.Entries)
            {
                if (entry.FileName == "song.desc")
                {
                    MemoryStream ms = new MemoryStream();
                    entry.Extract(ms);
                    string tempDesc = Encoding.UTF8.GetString(ms.ToArray());
                    JsonUtility.FromJsonOverwrite(tempDesc, audicaFile.desc);
                    ms.Dispose();
                    continue;
                }

                //Extract the cues files.
                else if (entry.FileName == "expert.cues")
                {
                    entry.Extract($"{appPath}/.cache");
                    expert = true;
                }
                else if (entry.FileName == "advanced.cues")
                {
                    entry.Extract($"{appPath}/.cache");
                    advanced = true;
                }
                else if (entry.FileName == "moderate.cues")
                {
                    entry.Extract($"{appPath}/.cache");
                    standard = true;
                }
                else if (entry.FileName == "beginner.cues")
                {
                    entry.Extract($"{appPath}/.cache");
                    easy = true;
                }
                else if (entry.FileName == "modifiers.json")
                {
                    entry.Extract($"{appPath}/.cache");
                    modifiers = true;
                }
            }

            //Load moggsongg, has to be done after desc is loaded
            if (audicaZip.ContainsEntry(audicaFile.desc.moggSong))
            {
                MemoryStream ms = new MemoryStream();
                audicaZip[audicaFile.desc.moggSong].Extract(ms);
                audicaFile.mainMoggSong = new MoggSong(ms);
                Debug.Log($"MoggSong volumes: L{audicaFile.mainMoggSong.volume.l}, R{audicaFile.mainMoggSong.volume.r} ");
                audicaZip[audicaFile.desc.moggSong].Extract($"{appPath}/.cache");
            }
            else
            {
                Debug.Log("Moggsong not found");
            }


            //Now we fill the audicaFile var with all the things it needs.
            //Remember, all props in audicaFile.desc refer to either moggsong or the name of the mogg.
            //Real clips are stored in main audicaFile object.

            //Load the cues files.
            if (expert)
            {
                audicaFile.diffs.expert = JsonUtility.FromJson <CueFile>(File.ReadAllText($"{appPath}/.cache/expert.cues"));
            }
            if (advanced)
            {
                audicaFile.diffs.advanced = JsonUtility.FromJson <CueFile>(File.ReadAllText($"{appPath}/.cache/advanced.cues"));
            }
            if (standard)
            {
                audicaFile.diffs.moderate = JsonUtility.FromJson <CueFile>(File.ReadAllText($"{appPath}/.cache/moderate.cues"));
            }
            if (easy)
            {
                audicaFile.diffs.beginner = JsonUtility.FromJson <CueFile>(File.ReadAllText($"{appPath}/.cache/beginner.cues"));
            }
            if (modifiers)
            {
                audicaFile.modifiers = JsonUtility.FromJson <ModifierList>(File.ReadAllText($"{appPath}/.cache/modifiers.json"));
            }

            MemoryStream temp = new MemoryStream();

            //Load the names of the moggs
            foreach (ZipEntry entry in audicaZip.Entries)
            {
                if (entry.FileName == audicaFile.desc.moggSong)
                {
                    entry.Extract(temp);
                    audicaFile.desc.moggMainSong = MoggSongParser.parse_metadata(Encoding.UTF8.GetString(temp.ToArray()))[0];
                }
                else if (entry.FileName == audicaFile.desc.sustainSongLeft)
                {
                    entry.Extract(temp);
                    audicaFile.desc.moggSustainSongLeft = MoggSongParser.parse_metadata(Encoding.UTF8.GetString(temp.ToArray()))[0];
                }
                else if (entry.FileName == audicaFile.desc.sustainSongRight)
                {
                    entry.Extract(temp);
                    audicaFile.desc.moggSustainSongRight = MoggSongParser.parse_metadata(Encoding.UTF8.GetString(temp.ToArray()))[0];
                }
                else if (entry.FileName == audicaFile.desc.fxSong)
                {
                    entry.Extract(temp);
                    audicaFile.desc.moggFxSong = MoggSongParser.parse_metadata(Encoding.UTF8.GetString(temp.ToArray()))[0];
                }
                else if (entry.FileName == "song.mid" || entry.FileName == audicaFile.desc.midiFile)
                {
                    string midiFiileName = $"{appPath}/.cache/song.mid";

                    entry.Extract($"{appPath}/.cache", ExtractExistingFileAction.OverwriteSilently);

                    if (entry.FileName != "song.mid")
                    {
                        File.Delete(midiFiileName);
                        File.Move($"{appPath}/.cache/" + audicaFile.desc.midiFile, midiFiileName);

                        //Sometimes these midi files get marked with strange attributes. Reset them to normal so we don't have problems deleting them
                        File.SetAttributes(midiFiileName, FileAttributes.Normal);
                    }

                    audicaFile.song_mid = new MidiFile(midiFiileName);

                    //Album art, just gonna shove it here
                }
                else if (entry.FileName == "song.png" || entry.FileName == audicaFile.desc.albumArt)
                {
                    string albumArtName = $"{appPath}/.cache/song.png";

                    entry.Extract($"{appPath}/.cache", ExtractExistingFileAction.OverwriteSilently);

                    if (entry.FileName != "song.png")
                    {
                        File.Delete(albumArtName);
                        File.Move($"{appPath}/.cache/" + audicaFile.desc.albumArt, albumArtName);
                    }

                    //audicaFile.song_png = new ArtFile(artFileName);
                }
                temp.SetLength(0);
            }


            bool mainSongCached = false, sustainRightCached = false, sustainLeftCached = false, extraSongCached = false;

            if (File.Exists($"{appPath}/.cache/{audicaFile.desc.cachedMainSong}.ogg"))
            {
                mainSongCached = true;
            }

            if (File.Exists($"{appPath}/.cache/{audicaFile.desc.cachedSustainSongRight}.ogg"))
            {
                sustainRightCached = true;
            }

            if (File.Exists($"{appPath}/.cache/{audicaFile.desc.cachedSustainSongLeft}.ogg"))
            {
                sustainLeftCached = true;
            }

            if (File.Exists($"{appPath}/.cache/{audicaFile.desc.cachedFxSong}.ogg"))
            {
                extraSongCached = true;
            }


            //If all the songs were already cached, skip this and go to the finish.
            if (mainSongCached && sustainRightCached && sustainLeftCached)
            {
                Debug.Log("Audio files were already cached and will be loaded.");
                goto Finish;
            }

            Debug.Log("Files not cached... Loading...");

            //If the files weren't cached, we now need to cache them manually then load them.
            MemoryStream tempMogg = new MemoryStream();

            foreach (ZipEntry entry in audicaZip.Entries)
            {
                if (!mainSongCached && entry.FileName == audicaFile.desc.moggMainSong)
                {
                    entry.Extract(tempMogg);
                    MoggToOgg(tempMogg.ToArray(), audicaFile.desc.cachedMainSong);
                }
                else if (!sustainRightCached && entry.FileName == audicaFile.desc.moggSustainSongRight)
                {
                    entry.Extract(tempMogg);
                    MoggToOgg(tempMogg.ToArray(), audicaFile.desc.cachedSustainSongRight);
                }
                else if (!sustainLeftCached && entry.FileName == audicaFile.desc.moggSustainSongLeft)
                {
                    entry.Extract(tempMogg);
                    MoggToOgg(tempMogg.ToArray(), audicaFile.desc.cachedSustainSongLeft);
                }
                else if (!extraSongCached && entry.FileName == audicaFile.desc.moggFxSong)
                {
                    entry.Extract(tempMogg);
                    MoggToOgg(tempMogg.ToArray(), audicaFile.desc.cachedFxSong);
                }

                tempMogg.SetLength(0);
            }

Finish:

            audicaFile.filepath = path;
            audicaZip.Dispose();

            return(audicaFile);
        }
Beispiel #4
0
        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");
             */
        }
Beispiel #6
0
        public static void ExportToAudicaFile(AudicaFile audicaFile)
        {
            if (!File.Exists(audicaFile.filepath))
            {
                Debug.Log("Save file is gone... :(");
                return;
            }

            Encoding encoding = Encoding.GetEncoding(437);

            using (var archive = ZipArchive.Open(audicaFile.filepath)) {
                HandleCache.CheckCacheFolderValid();
                HandleCache.CheckSaveFolderValid();

                bool expert = false, advanced = false, standard = false, easy = false;
                //Write the cues files to disk so we can add them to the audica file.
                if (audicaFile.diffs.expert.cues != null)
                {
                    File.WriteAllText($"{Application.dataPath}/.cache/expert-new.cues", CuesToJson(audicaFile.diffs.expert));
                    expert = true;
                }
                if (audicaFile.diffs.advanced.cues != null)
                {
                    File.WriteAllText($"{Application.dataPath}/.cache/advanced-new.cues", CuesToJson(audicaFile.diffs.advanced));
                    advanced = true;
                }
                if (audicaFile.diffs.moderate.cues != null)
                {
                    File.WriteAllText($"{Application.dataPath}/.cache/moderate-new.cues", CuesToJson(audicaFile.diffs.moderate));
                    standard = true;
                }
                if (audicaFile.diffs.beginner.cues != null)
                {
                    File.WriteAllText($"{Application.dataPath}/.cache/beginner-new.cues", CuesToJson(audicaFile.diffs.beginner));
                    easy = true;
                }

                File.WriteAllText($"{Application.dataPath}/.cache/song-new.desc", JsonUtility.ToJson(audicaFile.desc));

                var      workFolder = Path.Combine(Application.streamingAssetsPath, "Ogg2Audica");
                MidiFile songMidi   = MidiFile.Read(Path.Combine(workFolder, "songtemplate.mid"));

                using (var tempoMapManager = new TempoMapManager(new TicksPerQuarterNoteTimeDivision(480)))
                {
                    float    oneMinuteInMicroseconds = 60000000f;
                    TempoMap tempoMap = tempoMapManager.TempoMap;

                    foreach (var tempo in audicaFile.desc.tempoList)
                    {
                        tempoMapManager.SetTempo(new MetricTimeSpan((long)(tempo.time * 1000000)), new Tempo((long)(oneMinuteInMicroseconds / tempo.bpm)));
                    }

                    songMidi.ReplaceTempoMap(tempoMap);
                }

                songMidi.Write(Path.Combine(workFolder, $"{Application.dataPath}/.cache/song.mid"), true, MidiFileFormat.MultiTrack);

                //Remove any files we'll be replacing
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    if (entry.ToString() == "expert.cues")
                    {
                        archive.RemoveEntry(entry);
                    }
                    else if (entry.ToString() == "song.desc")
                    {
                        archive.RemoveEntry(entry);
                    }
                    else if (entry.ToString() == "song.mid")
                    {
                        archive.RemoveEntry(entry);
                    }
                    else if (entry.ToString() == "advanced.cues")
                    {
                        archive.RemoveEntry(entry);
                    }
                    else if (entry.ToString() == "moderate.cues")
                    {
                        archive.RemoveEntry(entry);
                    }
                    else if (entry.ToString() == "beginner.cues")
                    {
                        archive.RemoveEntry(entry);
                    }
                }
                if (expert)
                {
                    archive.AddEntry("expert.cues", $"{Application.dataPath}/.cache/expert-new.cues");
                }
                if (advanced)
                {
                    archive.AddEntry("advanced.cues", $"{Application.dataPath}/.cache/advanced-new.cues");
                }
                if (standard)
                {
                    archive.AddEntry("moderate.cues", $"{Application.dataPath}/.cache/moderate-new.cues");
                }
                if (easy)
                {
                    archive.AddEntry("beginner.cues", $"{Application.dataPath}/.cache/beginner-new.cues");
                }

                archive.AddEntry("song.desc", $"{Application.dataPath}/.cache/song-new.desc");
                archive.AddEntry("song.mid", $"{Application.dataPath}/.cache/song.mid");
                archive.SaveTo(audicaFile.filepath + ".temp", SharpCompress.Common.CompressionType.None);
                archive.Dispose();
            }
            File.Delete(audicaFile.filepath);
            File.Move(audicaFile.filepath + ".temp", audicaFile.filepath);


            Debug.Log("Export finished.");
        }
Beispiel #7
0
        public static void ExportToAudicaFile(AudicaFile audicaFile)
        {
            if (!File.Exists(audicaFile.filepath))
            {
                Debug.Log("Save file is gone... :(");
                return;
            }

            Encoding encoding = Encoding.GetEncoding(437);

            using (var archive = ZipArchive.Open(audicaFile.filepath)) {
                HandleCache.CheckCacheFolderValid();
                HandleCache.CheckSaveFolderValid();

                bool expert = false, advanced = false, standard = false, easy = false;
                //Write the cues files to disk so we can add them to the audica file.
                if (audicaFile.diffs.expert.cues != null)
                {
                    File.WriteAllText($"{Application.dataPath}/.cache/expert-new.cues", CuesToJson(audicaFile.diffs.expert));
                    expert = true;
                }
                if (audicaFile.diffs.advanced.cues != null)
                {
                    File.WriteAllText($"{Application.dataPath}/.cache/advanced-new.cues", CuesToJson(audicaFile.diffs.advanced));
                    advanced = true;
                }
                if (audicaFile.diffs.moderate.cues != null)
                {
                    File.WriteAllText($"{Application.dataPath}/.cache/moderate-new.cues", CuesToJson(audicaFile.diffs.moderate));
                    standard = true;
                }
                if (audicaFile.diffs.beginner.cues != null)
                {
                    File.WriteAllText($"{Application.dataPath}/.cache/beginner-new.cues", CuesToJson(audicaFile.diffs.beginner));
                    easy = true;
                }

                File.WriteAllText($"{Application.dataPath}/.cache/song-new.desc", JsonUtility.ToJson(audicaFile.desc));

                //Remove any files we'll be replacing
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    if (entry.ToString() == "expert.cues")
                    {
                        archive.RemoveEntry(entry);
                    }
                    else if (entry.ToString() == "song.desc")
                    {
                        archive.RemoveEntry(entry);
                    }
                    else if (entry.ToString() == "advanced.cues")
                    {
                        archive.RemoveEntry(entry);
                    }
                    else if (entry.ToString() == "moderate.cues")
                    {
                        archive.RemoveEntry(entry);
                    }
                    else if (entry.ToString() == "beginner.cues")
                    {
                        archive.RemoveEntry(entry);
                    }
                }
                if (expert)
                {
                    archive.AddEntry("expert.cues", $"{Application.dataPath}/.cache/expert-new.cues");
                }
                if (advanced)
                {
                    archive.AddEntry("advanced.cues", $"{Application.dataPath}/.cache/advanced-new.cues");
                }
                if (standard)
                {
                    archive.AddEntry("moderate.cues", $"{Application.dataPath}/.cache/moderate-new.cues");
                }
                if (easy)
                {
                    archive.AddEntry("beginner.cues", $"{Application.dataPath}/.cache/beginner-new.cues");
                }

                archive.AddEntry("song.desc", $"{Application.dataPath}/.cache/song-new.desc");
                archive.SaveTo(audicaFile.filepath + ".temp", SharpCompress.Common.CompressionType.None);
                archive.Dispose();
            }
            File.Delete(audicaFile.filepath);
            File.Move(audicaFile.filepath + ".temp", audicaFile.filepath);


            Debug.Log("Export finished.");
        }
        public static void ExportToAudicaFile(AudicaFile audicaFile, bool autoSave)
        {
            if (!File.Exists(audicaFile.filepath))
            {
                Debug.Log("Save file is gone... :(");
                return;
            }

            Encoding encoding     = Encoding.GetEncoding(437);
            string   targetPath   = audicaFile.filepath;
            string   autoSavePath = "";

            using (var archive = ZipArchive.Open(audicaFile.filepath)) {
                HandleCache.CheckCacheFolderValid();
                HandleCache.CheckSaveFolderValid();

                bool expert = false, advanced = false, standard = false, easy = false, modifiers = false;
                //Write the cues files to disk so we can add them to the audica file.
                if (audicaFile.diffs.expert.cues != null)
                {
                    File.WriteAllText($"{Application.dataPath}/.cache/expert-new.cues", CuesToJson(audicaFile.diffs.expert));
                    expert = true;
                }
                if (audicaFile.diffs.advanced.cues != null)
                {
                    File.WriteAllText($"{Application.dataPath}/.cache/advanced-new.cues", CuesToJson(audicaFile.diffs.advanced));
                    advanced = true;
                }
                if (audicaFile.diffs.moderate.cues != null)
                {
                    File.WriteAllText($"{Application.dataPath}/.cache/moderate-new.cues", CuesToJson(audicaFile.diffs.moderate));
                    standard = true;
                }
                if (audicaFile.diffs.beginner.cues != null)
                {
                    File.WriteAllText($"{Application.dataPath}/.cache/beginner-new.cues", CuesToJson(audicaFile.diffs.beginner));
                    easy = true;
                }
                audicaFile.modifiers           = new ModifierList();
                audicaFile.modifiers.modifiers = ModifierHandler.Instance.MapToDTO();
                if (audicaFile.modifiers.modifiers.Count > 0)
                {
                    File.WriteAllText($"{Application.dataPath}/.cache/modifiers-new.json", ModifiersToJson2(audicaFile.modifiers));
                    modifiers = true;
                }

                File.WriteAllText($"{Application.dataPath}/.cache/{audicaFile.desc.moggSong}", audicaFile.mainMoggSong.ExportToText());
                File.WriteAllText($"{Application.dataPath}/.cache/song-new.desc", Newtonsoft.Json.JsonConvert.SerializeObject(audicaFile.desc, Formatting.Indented));

                var      workFolder = Path.Combine(Application.streamingAssetsPath, "Ogg2Audica");
                MidiFile songMidi   = new MidiFile(Path.Combine(workFolder, "songtemplate.mid"));

                MidiEventCollection events = new MidiEventCollection(0, (int)Constants.PulsesPerQuarterNote);
                foreach (var tempo in audicaFile.desc.tempoList)
                {
                    events.AddEvent(new TempoEvent((int)tempo.microsecondsPerQuarterNote, (long)tempo.time.tick), 0);
                    events.AddEvent(new TimeSignatureEvent((long)tempo.time.tick, (int)tempo.timeSignature.Numerator, (int)TimeSignature.GetMIDIDenominator(tempo.timeSignature.Denominator), 0, 8), 0);
                }

                events.PrepareForExport();
                MidiFile.Export(Path.Combine(workFolder, $"{Application.dataPath}/.cache/song.mid"), events);


                //Remove any files we'll be replacing
                foreach (ZipArchiveEntry entry in archive.Entries)
                {
                    if (entry.ToString() == "expert.cues")
                    {
                        archive.RemoveEntry(entry);
                    }
                    else if (entry.ToString() == "song.desc")
                    {
                        archive.RemoveEntry(entry);
                    }
                    else if (entry.ToString() == audicaFile.desc.moggSong)
                    {
                        archive.RemoveEntry(entry);
                    }
                    else if (entry.ToString() == "song.mid")
                    {
                        archive.RemoveEntry(entry);
                    }
                    else if (entry.ToString() == "song.png")
                    {
                        archive.RemoveEntry(entry);
                    }
                    else if (entry.ToString() == "advanced.cues")
                    {
                        archive.RemoveEntry(entry);
                    }
                    else if (entry.ToString() == "moderate.cues")
                    {
                        archive.RemoveEntry(entry);
                    }
                    else if (entry.ToString() == "beginner.cues")
                    {
                        archive.RemoveEntry(entry);
                    }
                    else if (entry.ToString() == "modifiers.json")
                    {
                        archive.RemoveEntry(entry);
                    }
                }
                if (expert)
                {
                    archive.AddEntry("expert.cues", $"{Application.dataPath}/.cache/expert-new.cues");
                }
                if (advanced)
                {
                    archive.AddEntry("advanced.cues", $"{Application.dataPath}/.cache/advanced-new.cues");
                }
                if (standard)
                {
                    archive.AddEntry("moderate.cues", $"{Application.dataPath}/.cache/moderate-new.cues");
                }
                if (easy)
                {
                    archive.AddEntry("beginner.cues", $"{Application.dataPath}/.cache/beginner-new.cues");
                }
                if (modifiers)
                {
                    archive.AddEntry("modifiers.json", $"{Application.dataPath}/.cache/modifiers-new.json");
                }



                if (autoSave)
                {
                    int    pos       = audicaFile.filepath.LastIndexOf(@"\") + 1;
                    string fileName  = audicaFile.filepath.Substring(pos, audicaFile.filepath.Length - pos);
                    string shortName = fileName.Substring(0, fileName.LastIndexOf(@"."));
                    shortName    = shortName.Replace(" ", "");
                    targetPath   = $"{Application.dataPath}/autosaves/{shortName}/";
                    autoSavePath = targetPath;
                    targetPath  += DateTime.Now.ToString("MM-dd_h-mm-ss_");
                    targetPath  += fileName;
                    if (!Directory.Exists($"{Application.dataPath}/autosaves/"))
                    {
                        Directory.CreateDirectory($"{Application.dataPath}/autosaves/");
                    }
                    if (!Directory.Exists($"{Application.dataPath}/autosaves/{shortName}/"))
                    {
                        Directory.CreateDirectory($"{Application.dataPath}/autosaves/{shortName}/");
                    }
                }
                archive.AddEntry($"{audicaFile.desc.moggSong}", $"{Application.dataPath}/.cache/{audicaFile.desc.moggSong}");
                archive.AddEntry("song.desc", $"{Application.dataPath}/.cache/song-new.desc");
                archive.AddEntry("song.mid", $"{Application.dataPath}/.cache/song.mid");
                if (File.Exists($"{Application.dataPath}/.cache/song.png"))
                {
                    archive.AddEntry("song.png", $"{Application.dataPath}/.cache/song.png");
                }
                archive.SaveTo(audicaFile.filepath + ".temp", SharpCompress.Common.CompressionType.None);
                archive.Dispose();
            }
            File.Delete($"{Application.dataPath}/.cache/{audicaFile.desc.moggSong}");

            if (!autoSave)
            {
                File.Delete(audicaFile.filepath);
            }

            File.Move(audicaFile.filepath + ".temp", targetPath);


            if (autoSave)
            {
                NRSettings.autosavePath = autoSavePath;
            }
            Debug.Log("Export finished.");
        }