public static void ScanZSEQUENCE(string directory) // TODO make this folder identifiable, add directory and list of banks from scanned directory to this { // check if files were added by user to directory // we're not going to check for non-zseq here until I find an easy way to do that // Just going to trust users aren't stupid enough to think renaming a mp3 to zseq will work // format: FILENAME_InstrumentSet_Categories-separated-by-commas.zseq // where the filename, instrumentset, and categories are separated by single underscore foreach (String filePath in Directory.GetFiles(directory, "*.zseq")) { String filename = Path.GetFileName(filePath); // test if file has enough delimiters to separate data into name_bank_formats String[] pieces = filename.Split('_'); if (pieces.Length != 3) { continue; } byte[] input_seq_data = null; using (BinaryReader bank_reader = new BinaryReader(File.Open(Path.Combine(directory, filename), FileMode.Open))) { input_seq_data = new byte[((int)bank_reader.BaseStream.Length)]; bank_reader.Read(input_seq_data, 0, (int)bank_reader.BaseStream.Length); } SequenceBinaryData sequence_data = null; InstrumentSetInfo instrumnet_info = null; if (pieces[1].Contains("x")) //temporary, we can remove this now that we have MMRS, but maybe don't remove just yet { // load the custom bank for this file byte[] input_bank_data = null; String bank_name = filename.Substring(0, filename.LastIndexOf(".zseq")) + ".zbank"; using (BinaryReader bank_reader = new BinaryReader(File.Open(Path.Combine(directory, bank_name), FileMode.Open))) { input_bank_data = new byte[((int)bank_reader.BaseStream.Length)]; bank_reader.Read(input_bank_data, 0, (int)bank_reader.BaseStream.Length); } byte[] meta_data = new byte[8]; using (BinaryReader meta_reader = new BinaryReader(File.Open(Path.Combine(directory, bank_name.Substring(0, bank_name.LastIndexOf(".zbank")) + ".bankmeta"), FileMode.Open))) meta_reader.Read(meta_data, 0, meta_data.Length); pieces[1] = pieces[1].Replace("x", ""); instrumnet_info = new InstrumentSetInfo() { BankBinary = input_bank_data, BankMetaData = meta_data, BankSlot = Convert.ToInt32(pieces[1], 16), Modified = true }; } sequence_data = new SequenceBinaryData { SequenceBinary = input_seq_data, InstrumentSet = instrumnet_info }; var sourceName = filename; var sourceTypeString = pieces[2].Substring(0, pieces[2].Length - 5); var sourceInstrument = Convert.ToInt32(pieces[1], 16); //var sourceType = Array.ConvertAll(sourceTypeString.Split('-'), int.Parse).ToList(); List <int> sourceType = new List <int>(); foreach (String part in sourceTypeString.Split('-')) { sourceType.Add(Convert.ToInt32(part, 16)); } SequenceInfo sourceSequence = new SequenceInfo { Name = sourceName, Type = sourceType, Instrument = sourceInstrument, SequenceBinaryList = new List <SequenceBinaryData>() { sequence_data } }; RomData.SequenceList.Add(sourceSequence); } }
public static void ScanForMMRS(string directory) { // check if user has added mmrs packed sequence files to the music folder // mmrs is just a zip that has all the small files: // the sequence itself, the categories, and the instrument set value // if the song requires a custom audiobank, the bank and bank meta data are also here // the user should be able to pack the archive with multiple sequences and multiple banks to match, // where the redundancy increases likley hood of a song being able to be placed in a free audiobank slot foreach (String filePath in Directory.GetFiles(directory, "*.mmrs")) { try{ using (ZipArchive zip = ZipFile.OpenRead(filePath)) { List <string> sequences = new List <string>(); SequenceInfo new_song = new SequenceInfo();; String[] split_filepath = filePath.Split('\\'); new_song.Name = split_filepath[split_filepath.Length - 1]; //read categories file ZipArchiveEntry categories_entry = zip.GetEntry("categories.txt"); if (categories_entry != null) { List <int> category_list = new List <int>(); String category_string = new StreamReader(categories_entry.Open(), Encoding.Default).ReadToEnd(); char delimter = ','; if (category_string.Contains("-")) // someone will mess this up, its an easy thing to check for here tho { delimter = '-'; } else if (category_string.Contains("\n")) { delimter = '\n'; } foreach (String line in category_string.Split(delimter)) { category_list.Add(Convert.ToInt32(line, 16)); } new_song.Type = category_list; } else // there should always be one, if not, print error and skip { Debug.WriteLine("ERRROR: cannot find a categories file for " + new_song.Name); continue; } MD5 md5lib = MD5.Create(); foreach (ZipArchiveEntry zip_item in zip.Entries) { if (zip_item.Name.Contains("zseq")) { // read sequence binary file byte[] seq_data = new byte[zip_item.Length]; zip_item.Open().Read(seq_data, 0, seq_data.Length); SequenceBinaryData new_sequence_data = new SequenceBinaryData() { SequenceBinary = seq_data }; string file_name_extensionless = zip_item.Name.Substring(0, zip_item.Name.LastIndexOf(".zseq")); new_song.Instrument = Convert.ToInt32(file_name_extensionless, 16); // assuming we're naming with inst.zseq and inst.bank ZipArchiveEntry bank_entry = zip.GetEntry(zip_item.Name.Substring(0, zip_item.Name.LastIndexOf(".zseq")) + ".zbank"); if (bank_entry != null) // custom bank detected { // read bank file byte[] bank_data = new byte[bank_entry.Length]; bank_entry.Open().Read(bank_data, 0, bank_data.Length); // read bank meta data file ZipArchiveEntry meta_entry = zip.GetEntry(file_name_extensionless + ".bankmeta"); byte[] meta_data = new byte[meta_entry.Length]; meta_entry.Open().Read(meta_data, 0, meta_data.Length); new_sequence_data.InstrumentSet = new InstrumentSetInfo() { BankBinary = bank_data, BankSlot = new_song.Instrument, BankMetaData = meta_data, Modified = 1, Hash = BitConverter.ToInt64(md5lib.ComputeHash(bank_data), 0) }; }//if requires bank // multiple seq possible, add depending on if first or not if (new_song.SequenceBinaryList == null) { new_song.SequenceBinaryList = new List <SequenceBinaryData> { new_sequence_data } } ; else { new_song.SequenceBinaryList.Add(new_sequence_data); } } //is file zseq } // foreach zip entry if (new_song != null && new_song.SequenceBinaryList != null) { RomData.SequenceList.Add(new_song); } } // zip as file } // for each zip catch (Exception e) // log it, continue with other songs { Debug.WriteLine("Error attempting to read archive: " + filePath + " -- " + e); } } }
public static void ScanForMMRS(string directory) { // check if user has added mmrs packed sequence files to the music folder // mmrs is just a zip that has all the small files: // the sequence itself, the categories, and the instrument set value // if the song requires a custom audiobank, the bank and bank meta data are also here // if the song requires custom instrument samples, those are also here // the user should be able to pack the archive with multiple sequences and multiple banks to match, // where the redundancy increases likley hood of a song being able to be placed in a free audiobank slot MD5 md5lib = MD5.Create(); foreach (string filePath in Directory.GetFiles(directory, "*.mmrs")) { try { using (ZipArchive zip = ZipFile.OpenRead(filePath)) { var currentSong = new SequenceInfo();; var splitFilePath = filePath.Split('\\'); currentSong.Name = splitFilePath[splitFilePath.Length - 1]; //read categories file ZipArchiveEntry categoriesFileEntry = zip.GetEntry("categories.txt"); if (categoriesFileEntry != null) { var categoriesList = new List <int>(); var categoryData = new StreamReader(categoriesFileEntry.Open(), Encoding.Default).ReadToEnd(); var delimitingChar = ','; if (categoryData.Contains("-")) // someone will mess this up, its an easy thing to check for here tho { delimitingChar = '-'; } else if (categoryData.Contains("\n")) { delimitingChar = '\n'; } foreach (var line in categoryData.Split(delimitingChar)) { categoriesList.Add(Convert.ToInt32(line, 16)); } currentSong.Type = categoriesList; } else // there should always be one, if not, print error and skip { Debug.WriteLine("ERROR: cannot find a categories file for " + currentSong.Name); continue; } // read list of sound samples var samplesList = new List <SequenceSoundSampleBinaryData>(); foreach (ZipArchiveEntry zSoundFile in zip.Entries.Where(e => e.Name.Contains("zsound"))) { var sampleData = new byte[zSoundFile.Length]; zSoundFile.Open().Read(sampleData, 0, sampleData.Length); var sampleNameSplit = zSoundFile.Name.Split('_'); // everything before _ is a comment, readability, discard here var sampleName = sampleNameSplit.Length > 1 ? sampleNameSplit[sampleNameSplit.Length - 1] : zSoundFile.Name; sampleName = sampleName.Split('.')[0]; // we don't need the filetype after here either at this point uint sampleNameMarker = Convert.ToUInt32(sampleName, 16); samplesList.Add( new SequenceSoundSampleBinaryData() { BinaryData = sampleData, Addr = sampleNameMarker, Marker = sampleNameMarker, Hash = BitConverter.ToInt64(md5lib.ComputeHash(sampleData), 0) } ); } currentSong.InstrumentSamples = samplesList; // per sequence, read sequence and banks if needed foreach (ZipArchiveEntry zSeqFile in zip.Entries.Where(e => e.Name.Contains("zseq"))) { // read sequence binary file var zSeqData = new byte[zSeqFile.Length]; zSeqFile.Open().Read(zSeqData, 0, zSeqData.Length); var zSeq = new SequenceBinaryData() { SequenceBinary = zSeqData }; // zseq filename is the instrument set var fileNameInstrumentSet = zSeqFile.Name.Substring(0, zSeqFile.Name.LastIndexOf(".zseq")); currentSong.Instrument = Convert.ToInt32(fileNameInstrumentSet, 16); var bankFileEntry = zip.GetEntry(zSeqFile.Name.Substring(0, zSeqFile.Name.LastIndexOf(".zseq")) + ".zbank"); if (bankFileEntry != null) // custom bank detected { // read bank file byte[] zBankData = new byte[bankFileEntry.Length]; bankFileEntry.Open().Read(zBankData, 0, zBankData.Length); // read bankmeta file var bankmetaFileEntry = zip.GetEntry(fileNameInstrumentSet + ".bankmeta"); var bankmetaData = new byte[bankmetaFileEntry.Length]; bankmetaFileEntry.Open().Read(bankmetaData, 0, bankmetaData.Length); zSeq.InstrumentSet = new InstrumentSetInfo() { BankBinary = zBankData, BankSlot = currentSong.Instrument, BankMetaData = bankmetaData, Modified = 1, Hash = BitConverter.ToInt64(md5lib.ComputeHash(zBankData), 0), }; }//if requires bank // multiple seq possible, add depending on if first or not if (currentSong.SequenceBinaryList == null) { currentSong.SequenceBinaryList = new List <SequenceBinaryData> { zSeq }; } else { currentSong.SequenceBinaryList.Add(zSeq); } } // foreach zip entry if (currentSong != null && currentSong.SequenceBinaryList != null) { RomData.SequenceList.Add(currentSong); } } // zip as file } // for each zip catch (Exception e) // log it, continue with other songs { Debug.WriteLine("Error attempting to read archive: " + filePath + " -- " + e); } } }