private void makePsf2s(MkPsf2Struct pMkPsf2Struct, DoWorkEventArgs e) { string[] uniqueSqFiles; string[] uniqueHdFiles; if (!CancellationPending) { // get list of unique files uniqueSqFiles = this.getUniqueFileNames(pMkPsf2Struct.sourcePath, "*.SQ"); uniqueHdFiles = this.getUniqueFileNames(pMkPsf2Struct.sourcePath, "*.HD"); if (uniqueSqFiles != null) { if (pMkPsf2Struct.TryCombinations) { this.maxFiles = uniqueSqFiles.Length * uniqueHdFiles.Length; } else { this.maxFiles = uniqueSqFiles.Length; } // verify we do not have more than one HD/BD pair if a psf2lib is desired if (pMkPsf2Struct.CreatePsf2lib) { this.maxFiles++; if (uniqueHdFiles.Length > 1) { this.progressStruct.Clear(); this.progressStruct.ErrorMessage = String.Format("ERROR: More than 1 HD/BD pair detected, please only include 1 HD/BD pair when making .psf2lib files{0}", Environment.NewLine); ReportProgress(this.progress, this.progressStruct); return; } } this.buildPsf2s(uniqueSqFiles, uniqueHdFiles, pMkPsf2Struct, e); } } else { e.Cancel = true; return; } return; }
private void makePsf2s(MkPsf2Struct pMkPsf2Struct, DoWorkEventArgs e) { string[] uniqueSqFiles; if (!CancellationPending) { // get list of unique files uniqueSqFiles = this.getUniqueFileNames(pMkPsf2Struct.sourcePath); if (uniqueSqFiles != null) { this.maxFiles = uniqueSqFiles.Length; this.buildPsf2s(uniqueSqFiles, pMkPsf2Struct, e); } } else { e.Cancel = true; return; } return; }
protected override void OnDoWork(DoWorkEventArgs e) { MkPsf2Struct mkPsf2StructStruct = (MkPsf2Struct)e.Argument; this.makePsf2s(mkPsf2StructStruct, e); }
private void makePsf2File(MkPsf2Struct pMkPsf2Struct, string sqName, string hdName, string bdName, string makePsf2DestinationPath) { Process makePsf2Process; StringBuilder sqArguments = new StringBuilder(); string sqFileName = String.Empty; string destinationSqFile = String.Empty; string hdFileName = String.Empty; string destinationHdFile = String.Empty; string bdFileName = String.Empty; string destinationBdFile = String.Empty; string destinationPsf2Irx = Path.Combine(WORKING_FOLDER, "psf2.irx"); string destinationSqIrx = Path.Combine(WORKING_FOLDER, "sq.irx"); string destinationLibSdIrx = Path.Combine(WORKING_FOLDER, "LIBSD.IRX"); string destinationModHsynIrx = Path.Combine(WORKING_FOLDER, "MODHSYN.IRX"); string destinationModMidiIrx = Path.Combine(WORKING_FOLDER, "MODMIDI.IRX"); int totalSequences = 0; string outputFile; string outputFileExtension; // report progress this.progress = (++this.fileCount * 100) / maxFiles; this.progressStruct.Clear(); this.progressStruct.FileName = sqName; ReportProgress(progress, this.progressStruct); try { // copy data files to working directory string filePrefix; string outputFilePrefix; if (pMkPsf2Struct.TryCombinations) { filePrefix = String.Format("S({0})_H({1})", Path.GetFileNameWithoutExtension(sqName), Path.GetFileNameWithoutExtension(hdName)); } else { filePrefix = Path.GetFileNameWithoutExtension(sqName); } // copy files to working dir if they exist if ((!pMkPsf2Struct.CreatePsf2lib) || (pMkPsf2Struct.CreatePsf2lib && String.IsNullOrEmpty(sqName))) { // copy generic modules to working directory File.Copy(Path.Combine(MODULES_FOLDER, "psf2.irx"), destinationPsf2Irx, true); File.Copy(Path.Combine(MODULES_FOLDER, "sq.irx"), destinationSqIrx, true); // copy source modules to working directory File.Copy(Path.Combine(pMkPsf2Struct.modulePath, "LIBSD.IRX"), destinationLibSdIrx, true); File.Copy(Path.Combine(pMkPsf2Struct.modulePath, "MODHSYN.IRX"), destinationModHsynIrx, true); File.Copy(Path.Combine(pMkPsf2Struct.modulePath, "MODMIDI.IRX"), destinationModMidiIrx, true); } hdFileName = Path.GetFileName(hdName); bdFileName = Path.GetFileName(bdName); if ((!pMkPsf2Struct.CreatePsf2lib) || (pMkPsf2Struct.CreatePsf2lib && String.IsNullOrEmpty(sqName))) { destinationHdFile = Path.Combine(WORKING_FOLDER, hdFileName); destinationBdFile = Path.Combine(WORKING_FOLDER, bdFileName); File.Copy(hdName, destinationHdFile); File.Copy(bdName, destinationBdFile); } if (!String.IsNullOrEmpty(sqName)) { sqFileName = Path.GetFileName(sqName); destinationSqFile = Path.Combine(WORKING_FOLDER, sqFileName); File.Copy(sqName, destinationSqFile); totalSequences = getTotalSequenceCount(destinationSqFile); for (int i = 0; i < totalSequences; i++) { if (validSequenceArray[i]) { sqArguments = new StringBuilder(); if (totalSequences > 1) { outputFilePrefix = filePrefix + "_" + i.ToString("X2"); sqArguments.Append(String.Format(" -n={0}", i)); } else { outputFilePrefix = filePrefix; } // write ini file string iniPath = Path.Combine(WORKING_FOLDER, "psf2.ini"); StreamWriter sw = File.CreateText(iniPath); sw.WriteLine("libsd.irx"); sw.WriteLine("modhsyn.irx"); sw.WriteLine("modmidi.irx"); // build sq.irx arguments sqArguments.Append(String.IsNullOrEmpty(pMkPsf2Struct.reverb.Trim()) ? " -r=5" : String.Format(" -r={0}", pMkPsf2Struct.reverb.Trim())); sqArguments.Append(String.IsNullOrEmpty(pMkPsf2Struct.depth.Trim()) ? " -d=16383" : String.Format(" -d={0}", pMkPsf2Struct.depth.Trim())); sqArguments.Append(String.IsNullOrEmpty(pMkPsf2Struct.tickInterval.Trim()) ? String.Empty : String.Format(" -u={0}", pMkPsf2Struct.tickInterval.Trim())); sqArguments.Append(String.IsNullOrEmpty(pMkPsf2Struct.tempo.Trim()) ? String.Empty : String.Format(" -t={0}", pMkPsf2Struct.tempo.Trim())); sqArguments.Append(String.IsNullOrEmpty(pMkPsf2Struct.volume.Trim()) ? String.Empty : String.Format(" -v={0}", pMkPsf2Struct.volume.Trim())); sqArguments.Append(String.Format(" -s={0} -h={1} -b={2}", sqFileName, hdFileName, bdFileName)); sw.WriteLine(String.Format("sq.irx {0}", sqArguments.ToString())); sw.Close(); sw.Dispose(); // set output extension if (pMkPsf2Struct.CreatePsf2lib) { outputFileExtension = ".minipsf2"; } else { outputFileExtension = ".psf2"; } // run makepsf2 outputFile = String.Format("{0}{1}", outputFilePrefix, outputFileExtension); string arguments = String.Format(" {0} {1}", outputFile, WORKING_FOLDER); makePsf2Process = new Process(); makePsf2Process.StartInfo = new ProcessStartInfo(makePsf2DestinationPath, arguments); makePsf2Process.StartInfo.UseShellExecute = false; makePsf2Process.StartInfo.CreateNoWindow = true; bool isSuccess = makePsf2Process.Start(); makePsf2Process.WaitForExit(); if (isSuccess) { // add lib tag if (pMkPsf2Struct.CreatePsf2lib) { using (FileStream ofs = File.Open(outputFile, FileMode.Open, FileAccess.Write)) { ofs.Seek(0, SeekOrigin.End); using (BinaryWriter bw = new BinaryWriter(ofs)) { System.Text.Encoding enc = System.Text.Encoding.ASCII; bw.Write(enc.GetBytes(Xsf.ASCII_TAG)); // [TAG] bw.Write(enc.GetBytes(String.Format("_lib={0}", pMkPsf2Struct.Psf2LibName))); bw.Write(new byte[] { 0x0A }); } } } this.progressStruct.Clear(); this.progressStruct.GenericMessage = String.Format("{0} created.{1}", outputFile, Environment.NewLine); ReportProgress(Constants.ProgressMessageOnly, this.progressStruct); if (!Directory.Exists(Path.Combine(OUTPUT_FOLDER, pMkPsf2Struct.outputFolder))) { Directory.CreateDirectory(Path.Combine(OUTPUT_FOLDER, pMkPsf2Struct.outputFolder)); } File.Move(outputFile, Path.Combine(Path.Combine(OUTPUT_FOLDER, pMkPsf2Struct.outputFolder), outputFile)); } File.Delete(iniPath); } // if (validSequenceArray[i]) else if (totalSequences == 1) { this.progressStruct.Clear(); this.progressStruct.GenericMessage = String.Format("WARNING: {0}.SQ has only ONE sequence and it is INVALID. Skipping...", filePrefix) + Environment.NewLine; ReportProgress(Constants.ProgressMessageOnly, this.progressStruct); } } // for (int i = 0; i < totalSequences; i++) } else // make .psf2lib with HD/BD only { // run makepsf2 string arguments = String.Format(" {0} {1}", pMkPsf2Struct.Psf2LibName, WORKING_FOLDER); makePsf2Process = new Process(); makePsf2Process.StartInfo = new ProcessStartInfo(makePsf2DestinationPath, arguments); makePsf2Process.StartInfo.UseShellExecute = false; makePsf2Process.StartInfo.CreateNoWindow = true; bool isSuccess = makePsf2Process.Start(); makePsf2Process.WaitForExit(); if (isSuccess) { this.progressStruct.Clear(); this.progressStruct.GenericMessage = String.Format("{0} created.{1}", pMkPsf2Struct.Psf2LibName, Environment.NewLine); ReportProgress(Constants.ProgressMessageOnly, this.progressStruct); if (!Directory.Exists(Path.Combine(OUTPUT_FOLDER, pMkPsf2Struct.outputFolder))) { Directory.CreateDirectory(Path.Combine(OUTPUT_FOLDER, pMkPsf2Struct.outputFolder)); } File.Move(pMkPsf2Struct.Psf2LibName, Path.Combine(Path.Combine(OUTPUT_FOLDER, pMkPsf2Struct.outputFolder), pMkPsf2Struct.Psf2LibName)); } // delete modules from working dir if (File.Exists(destinationPsf2Irx)) { File.Delete(destinationPsf2Irx); } if (File.Exists(destinationSqIrx)) { File.Delete(destinationSqIrx); } if (File.Exists(destinationLibSdIrx)) { File.Delete(destinationLibSdIrx); } if (File.Exists(destinationModHsynIrx)) { File.Delete(destinationModHsynIrx); } if (File.Exists(destinationModMidiIrx)) { File.Delete(destinationModMidiIrx); } } // delete files if needed if (File.Exists(destinationSqFile)) { File.Delete(destinationSqFile); } if (File.Exists(destinationHdFile)) { File.Delete(destinationHdFile); } if (File.Exists(destinationBdFile)) { File.Delete(destinationBdFile); } } catch (Exception ex2) { this.progressStruct.Clear(); this.progressStruct.FileName = sqName; this.progressStruct.ErrorMessage = String.Format("{0}{1}", ex2.Message, Environment.NewLine); ReportProgress(progress, this.progressStruct); } }
private void buildPsf2s(string[] pUniqueSqFiles, string[] pUniqueHdFiles, MkPsf2Struct pMkPsf2Struct, DoWorkEventArgs e) { string makePsf2SourcePath = Path.Combine(PROGRAMS_FOLDER, "mkpsf2.exe"); string makePsf2DestinationPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "mkpsf2.exe"); // setup working directory try { Directory.CreateDirectory(WORKING_FOLDER); // copy program File.Copy(makePsf2SourcePath, makePsf2DestinationPath, true); } catch (Exception ex) { this.progressStruct.Clear(); this.progressStruct.ErrorMessage = ex.Message; ReportProgress(0, this.progressStruct); return; } // build psf2lib try { // make psf2lib first if (pMkPsf2Struct.CreatePsf2lib) { this.makePsf2File(pMkPsf2Struct, null, pUniqueHdFiles[0], Path.ChangeExtension(pUniqueHdFiles[0], ".bd"), makePsf2DestinationPath); } } catch (Exception psf2libEx) { this.progressStruct.Clear(); this.progressStruct.FileName = pMkPsf2Struct.Psf2LibName; this.progressStruct.ErrorMessage = psf2libEx.Message; ReportProgress(this.progress, this.progressStruct); } foreach (string f in pUniqueSqFiles) { if (!CancellationPending) { if (pMkPsf2Struct.TryCombinations) { foreach (string hdFile in pUniqueHdFiles) { try { this.makePsf2File(pMkPsf2Struct, f, hdFile, Path.ChangeExtension(hdFile, ".bd"), makePsf2DestinationPath); } catch (Exception ex) { this.progressStruct.Clear(); this.progressStruct.FileName = String.Format("S({0})_H({1})", Path.GetFileNameWithoutExtension(f), Path.GetFileNameWithoutExtension(hdFile)); this.progressStruct.ErrorMessage = ex.Message; ReportProgress(this.progress, this.progressStruct); } } } else { try { if (!pMkPsf2Struct.CreatePsf2lib) { this.makePsf2File(pMkPsf2Struct, f, Path.ChangeExtension(f, ".hd"), Path.ChangeExtension(f, ".bd"), makePsf2DestinationPath); } else { this.makePsf2File(pMkPsf2Struct, f, pUniqueHdFiles[0], Path.ChangeExtension(pUniqueHdFiles[0], ".bd"), makePsf2DestinationPath); } } catch (Exception ex) { this.progressStruct.Clear(); this.progressStruct.FileName = f; this.progressStruct.ErrorMessage = ex.Message; ReportProgress(this.progress, this.progressStruct); } } } else { e.Cancel = true; return; } // if (!CancellationPending) } // foreach (string f in pUniqueSqFiles) // cleanup working folder try { Directory.Delete(WORKING_FOLDER, true); File.Delete(makePsf2DestinationPath); } catch (Exception ex3) { this.progressStruct.Clear(); this.progressStruct.ErrorMessage = ex3.Message; ReportProgress(100, this.progressStruct); } }
private void buildPsf2s(string[] pUniqueSqFiles, MkPsf2Struct pMkPsf2Struct, DoWorkEventArgs e) { Process makePsf2Process; VGMToolbox.util.ProgressStruct vProgressStruct = new VGMToolbox.util.ProgressStruct(); string makePsf2SourcePath = Path.Combine(PROGRAMS_FOLDER, "mkpsf2.exe"); string makePsf2DestinationPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "mkpsf2.exe"); try { Directory.CreateDirectory(WORKING_FOLDER); // copy generic modules to working directory File.Copy(Path.Combine(MODULES_FOLDER, "psf2.irx"), Path.Combine(WORKING_FOLDER, "psf2.irx"), true); File.Copy(Path.Combine(MODULES_FOLDER, "sq.irx"), Path.Combine(WORKING_FOLDER, "sq.irx"), true); // copy source modules to working directory File.Copy(Path.Combine(pMkPsf2Struct.modulePath, "LIBSD.IRX"), Path.Combine(WORKING_FOLDER, "LIBSD.IRX"), true); File.Copy(Path.Combine(pMkPsf2Struct.modulePath, "MODHSYN.IRX"), Path.Combine(WORKING_FOLDER, "MODHSYN.IRX"), true); File.Copy(Path.Combine(pMkPsf2Struct.modulePath, "MODMIDI.IRX"), Path.Combine(WORKING_FOLDER, "MODMIDI.IRX"), true); // copy program File.Copy(makePsf2SourcePath, makePsf2DestinationPath, true); } catch (Exception ex) { vProgressStruct = new VGMToolbox.util.ProgressStruct(); vProgressStruct.NewNode = null; vProgressStruct.FileName = null; vProgressStruct.ErrorMessage = ex.Message; ReportProgress(0, vProgressStruct); return; } foreach (string f in pUniqueSqFiles) { if (!CancellationPending) { StringBuilder sqArguments = new StringBuilder(); // report progress int progress = (++this.fileCount * 100) / maxFiles; vProgressStruct = new VGMToolbox.util.ProgressStruct(); vProgressStruct.NewNode = null; vProgressStruct.FileName = f; ReportProgress(progress, vProgressStruct); try { // copy data files to working directory string filePrefix = Path.GetFileNameWithoutExtension(f); string sourceDirectory = Path.GetDirectoryName(f); string bdFileName = filePrefix + ".bd"; string hdFileName = filePrefix + ".hd"; string sqFileName = filePrefix + ".sq"; string sourceBdFile = Path.Combine(sourceDirectory, bdFileName); string sourceHdFile = Path.Combine(sourceDirectory, hdFileName); string sourceSqFile = Path.Combine(sourceDirectory, sqFileName); string destinationBdFile = Path.Combine(WORKING_FOLDER, bdFileName); string destinationHdFile = Path.Combine(WORKING_FOLDER, hdFileName); string destinationSqFile = Path.Combine(WORKING_FOLDER, sqFileName); File.Copy(sourceBdFile, destinationBdFile); File.Copy(sourceHdFile, destinationHdFile); File.Copy(sourceSqFile, destinationSqFile); // write ini file string iniPath = Path.Combine(WORKING_FOLDER, "psf2.ini"); StreamWriter sw = File.CreateText(iniPath); sw.WriteLine("libsd.irx"); sw.WriteLine("modhsyn.irx"); sw.WriteLine("modmidi.irx"); // build sq.irx arguments sqArguments.Append(String.IsNullOrEmpty(pMkPsf2Struct.reverb.Trim()) ? " -r=5" : String.Format(" -r={0}", pMkPsf2Struct.reverb.Trim())); sqArguments.Append(String.IsNullOrEmpty(pMkPsf2Struct.depth.Trim()) ? " -d=16383" : String.Format(" -d={0}", pMkPsf2Struct.depth.Trim())); sqArguments.Append(String.IsNullOrEmpty(pMkPsf2Struct.tickInterval.Trim()) ? String.Empty : String.Format(" -u={0}", pMkPsf2Struct.tickInterval.Trim())); sqArguments.Append(String.IsNullOrEmpty(pMkPsf2Struct.tempo.Trim()) ? String.Empty : String.Format(" -t={0}", pMkPsf2Struct.tempo.Trim())); sqArguments.Append(String.IsNullOrEmpty(pMkPsf2Struct.volume.Trim()) ? String.Empty : String.Format(" -v={0}", pMkPsf2Struct.volume.Trim())); sqArguments.Append(String.Format(" -s={0} -h={1} -b={2}", sqFileName, hdFileName, bdFileName)); //sw.WriteLine(String.Format("sq.irx -r=5 -d=16383 -s={0} -h={1} -b={2}", // sqFileName, hdFileName, bdFileName)); sw.WriteLine(String.Format("sq.irx {0}", sqArguments.ToString())); sw.Close(); sw.Dispose(); // run makepsf2 string arguments = String.Format(" {0}.psf2 {1}", filePrefix, WORKING_FOLDER); makePsf2Process = new Process(); makePsf2Process.StartInfo = new ProcessStartInfo(makePsf2DestinationPath, arguments); makePsf2Process.StartInfo.UseShellExecute = false; makePsf2Process.StartInfo.CreateNoWindow = true; bool isSuccess = makePsf2Process.Start(); makePsf2Process.WaitForExit(); if (isSuccess) { vProgressStruct = new VGMToolbox.util.ProgressStruct(); vProgressStruct.NewNode = null; vProgressStruct.GenericMessage = String.Format("{0}.psf2 created.", filePrefix) + Environment.NewLine; ReportProgress(Constants.ProgressMessageOnly, vProgressStruct); File.Move(filePrefix + ".psf2", Path.Combine(OUTPUT_FOLDER, filePrefix + ".psf2")); } File.Delete(destinationBdFile); File.Delete(destinationHdFile); File.Delete(destinationSqFile); File.Delete(iniPath); } catch (Exception ex2) { vProgressStruct = new VGMToolbox.util.ProgressStruct(); vProgressStruct.NewNode = null; vProgressStruct.FileName = f; vProgressStruct.ErrorMessage = ex2.Message; ReportProgress(progress, vProgressStruct); } } else { e.Cancel = true; return; } } // foreach try { Directory.Delete(WORKING_FOLDER, true); File.Delete(makePsf2DestinationPath); } catch (Exception ex3) { vProgressStruct = new VGMToolbox.util.ProgressStruct(); vProgressStruct.NewNode = null; vProgressStruct.FileName = null; vProgressStruct.ErrorMessage = ex3.Message; ReportProgress(100, vProgressStruct); } }