private void ExecuteConversion(FileType fileType) { long dt2compare = GetInputFileLastTimeModified(inputFilename); if (dt2compare != inputfileLastModified) { inputfileLastModified = dt2compare; //MainFactory.LoadXrns(inputFileName); SongDataFactory songDataFactory = new SongDataFactory(); songDataFactory.ReportProgress += load_XrnsEvent; RenoiseSong renoiseSong = songDataFactory.ExtractRenoiseSong(inputFilename); songData = songDataFactory.ExtractSongData(renoiseSong, inputFilename); } byte[] outputStream = new byte[0]; processInfo = new ProcessInfo(); //MainFactory.ReportProgress -= new ProgressHandler(_loadModule_ReportProgress); //MainFactory.ReportProgress -= new ProgressHandler(_converterFactory_ReportProgress); //MainFactory.ReportProgress += new ProgressHandler(_converterFactory_ReportProgress); RunBWorker4WritingModule(outputFileName, fileType); isConversionTypeChanged = false; }
public SongData ExtractSongData(RenoiseSong renoiseSong, string filename) { SongData songData = new SongData(); //int[] tracksPositionMap = GenerateChannelsPositionMapAccordingToSubColumns(renoiseSong.Tracks.SequencerTrack); int masterTracksTotalColumns = GetMasterTracksTotalColumns(renoiseSong.Tracks.SequencerMasterTrack); songData.Name = renoiseSong.GlobalSongData.SongName; songData.LinesPerBeat = renoiseSong.GlobalSongData.LinesPerBeat; songData.SampleOffsetCompatibilityMode = renoiseSong.GlobalSongData.SampleOffsetCompatibilityMode; songData.PitchCompatibilityMode = renoiseSong.GlobalSongData.PitchEffectsCompatibilityMode; songData.PlaybackEngineVersion = renoiseSong.GlobalSongData.PlaybackEngineVersion; songData.TicksPerLine = renoiseSong.GlobalSongData.TicksPerLine; songData.NumChannels = GetNumChannels(renoiseSong.Tracks.SequencerTrack); songData.NumInstruments = renoiseSong.Instruments.Instrument.Length; songData.NumMasterTracksColumns = masterTracksTotalColumns; songData.InitialBPM = Convert.ToInt16(renoiseSong.GlobalSongData.BeatsPerMin); songData.LinesPerBeat = renoiseSong.GlobalSongData.LinesPerBeat; songData.RestartPosition = renoiseSong.PatternSequence.LoopSelection.CursorPos; songData.PatternOrderTable = GetPatternOrderTable(renoiseSong.PatternSequence.SequenceEntries.SequenceEntry); songData.Instruments = GetInstrumentsData(renoiseSong.Instruments.Instrument); songData.Patterns = GetPatternData(renoiseSong.PatternPool.Patterns.Pattern, renoiseSong.Tracks.SequencerTrack, masterTracksTotalColumns); LoadFromIni(songData, filename); return(songData); }
public void ConversionTest(string path, string hash) { songDataFactory = new SongDataFactory(); songDataFactory.ReportProgress += ReportProgress; //Console.WriteLine("ConversionTest...."); //string input = this.TestContext.Properties["resource_path"].ToString() + resourceAttribute.Path; string input = "resources/examples/" + path; RenoiseSong renoiseSong = songDataFactory.ExtractRenoiseSong(input); songData = songDataFactory.ExtractSongData(renoiseSong, input); converter = new ModConverter(input); converter.EventProgress += ReportProgress; settings = new ModSettings(); settings.ForceProTrackerCompatibility = PROTRACKER_COMPATIBILITY_MODE.NONE; settings.NtscMode = true; settings.PortamentoLossThreshold = 2; settings.VolumeScalingMode = VOLUME_SCALING_MODE.SAMPLE; converter.Settings = settings; byte[] bytes = converter.Convert(songData); string hashGen = MD5Utils.GenerateMd5Hash(bytes); //Write file for later investigation string outputFile = input.Remove(input.Length - 5); // default output file, same as input without .xrns extension outputFile = System.Text.RegularExpressions.Regex.Match(outputFile, @"(?:(?!\.(mod|xm)$).)*").Value; string outputFileExt = System.Text.RegularExpressions.Regex.Match(outputFile, @"\.(mod | xm)$").Value; string destType = "mod"; // add extension to output file in case user has not already specified it if (!outputFileExt.Equals("." + destType, StringComparison.CurrentCultureIgnoreCase)) { outputFile += '.' + destType; } Utility.SaveByteArrayToFile(outputFile, bytes); //So is it what we wanted? Assert.AreEqual(hash, hashGen); }
public void Save(RenoiseSong song, string fileName) { var songData = Utils.Serializer(song); using (var fileStream = new FileStream(fileName, FileMode.Create)) { using (ZipArchive archive = new ZipArchive(fileStream, ZipArchiveMode.Create)) { var entry = archive.CreateEntry("Song.xml"); using (StreamWriter writer = new StreamWriter(entry.Open())) { writer.Write(songData); } } } }
private void backgroundWorker1_DoWork_LoadFile(object sender, DoWorkEventArgs e) { string filename = (string)e.Argument; BackgroundWorker bw = sender as BackgroundWorker; bw.ReportProgress(0, "Loading xrns data..."); SongDataFactory songDataFactory = new SongDataFactory(); songDataFactory.ReportProgress += load_XrnsEvent; RenoiseSong renoiseSong = songDataFactory.ExtractRenoiseSong(filename); songData = songDataFactory.ExtractSongData(renoiseSong, filename); e.Result = filename; }
public RenoiseSong ExtractRenoiseSong(string filename) { FileStream fs = new FileStream(filename, FileMode.Open, FileAccess.Read); ZipFile zipFile = new ZipFile(fs); ZipEntry zipEntry = zipFile.GetEntry("Song.xml"); StreamReader songStream = new StreamReader(zipFile.GetInputStream(zipEntry)); XmlSerializer xmlSerializer = new XmlSerializer(typeof(RenoiseSong)); RenoiseSong renoiseSong = (RenoiseSong)xmlSerializer.Deserialize(songStream); try { int docVersion = renoiseSong.doc_version; if (Array.BinarySearch(COMPATIBILITY_SCHEMA_LIST, docVersion) < 0) { throw new XrnsException("Song version is not supported by this Xrns2XMod version. Try to save it with a " + "renoise compatible version (check the homepage for more info)"); } } finally { if (fs != null) { fs.Close(); } if (songStream != null) { songStream.Close(); } if (zipFile != null) { zipFile.Close(); } } return(renoiseSong); }
public void ConversionTest(string path, string hash) { songDataFactory = new SongDataFactory(); songDataFactory.ReportProgress += ReportProgress; string input = "resources/examples/" + path; RenoiseSong renoiseSong = songDataFactory.ExtractRenoiseSong(input); songData = songDataFactory.ExtractSongData(renoiseSong, input); converter = new XMConverter(input); settings = new XmSettings(); settings.Tempo = songData.InitialBPM; settings.TicksRow = songData.TicksPerLine; converter.Settings = settings; converter.EventProgress += ReportProgress; byte[] bytes = converter.Convert(songData); string hashGen = MD5Utils.GenerateMd5Hash(bytes); //Write file for later investigation string outputFile = input.Remove(input.Length - 5); // default output file, same as input without .xrns extension outputFile = System.Text.RegularExpressions.Regex.Match(outputFile, @"(?:(?!\.(mod|xm)$).)*").Value; string outputFileExt = System.Text.RegularExpressions.Regex.Match(outputFile, @"\.(mod | xm)$").Value; string destType = "xm"; // add extension to output file in case user has not already specified it if (!outputFileExt.Equals("." + destType, StringComparison.CurrentCultureIgnoreCase)) { outputFile += '.' + destType; } Utility.SaveByteArrayToFile(outputFile, bytes); //So is it what we wanted? Assert.AreEqual(hash, hashGen); }
public RenoiseSong Process(string fileName) { var song = new RenoiseSong(); using (FileStream zipFile = new FileStream(fileName, FileMode.Open)) { using (ZipArchive archive = new ZipArchive(zipFile, ZipArchiveMode.Read)) { foreach (var zipEntry in archive.Entries) { if (zipEntry.Name == "Song.xml") { var serializer = new XmlSerializer(typeof(RenoiseSong)); song = (RenoiseSong)serializer.Deserialize(zipEntry.Open()); break; } } } } return(song); }
static int Main(string[] args) { int retcode = 0; try { string destType = "xm"; //bool convfreq = false; string ptmode = "H"; bool ptNtsc = false; string volumeScalingMode = "S"; bool downgrade = false; bool replaceZK = false; //int fpl = 0; //int fvl = 0; string outputFile = string.Empty; string outputLog = null; string bassEmail = null; string bassCode = null; int portamentoLossThreshold = 2; int tempo = 0; int ticks = 0; var p = new OptionSet() { { "t|type=", "the destination format type (xm|mod).", v => destType = v }, //{ "convfreq", "convert all sample frequency to 8363 Hz (affects only mod)", // v => convfreq = v != null }, { "ptmode=", "ProTracker compatibility (affects only mod) (N(one)|S(oftware)|H(ardware)) (default: Hardware)", v => ptmode = v }, { "ntsc=", "ProTracker Region (affects only mod) (default: false)", v => ptNtsc = v == null || Boolean.Parse(v) == true }, { "volscal|volumescaling=", "volume scaling mode (N(one)|S(ample)|C(olumn))", v => volumeScalingMode = v }, { "tempo=", "the initial tempo value (affects only xm)", v => tempo = int.Parse(v) }, { "ticks=", "the initial ticks/row value (affects only xm)", v => ticks = int.Parse(v) }, //{ "fpl=", "Apply Fine pitch not beyond x value (0 - 15)", // (int v) => fpl = v }, //{ "fvl=", "Apply Fine volume not beyond x value (0 - 15)", // (int v) => fvl = v }, { "portresh=", "Portamento treshold value (0-4, default: 2) (affects only mod)", (int v) => portamentoLossThreshold = v }, { "out=", "the <output-file>", v => outputFile = v }, { "log=", "the <output-log>", v => outputLog = v }, { "bass_email=", "bass registered email", v => bassEmail = v }, { "bass_code=", "bass registered code", v => bassCode = v }, //{ "downgrade", "downgrade playback engine to TIMING MODEL SPEED", // v => downgrade = v != null }, //{ "replaceZK", "(downgrade mode) Replace ZK with ZL command", // v => replaceZK = v != null }, }; List <string> extra; try { extra = p.Parse(args); } catch (OptionException e) { Console.WriteLine(e.Message); return(-1); } if (args.Length < 1) { PrintUsage(p); } else { string inputFile; if (extra.Count == 1) { inputFile = extra[0]; if (!File.Exists(inputFile) || !Path.GetExtension(inputFile).Equals(".xrns", StringComparison.InvariantCultureIgnoreCase)) { throw new ApplicationException("A valid xrns input file must be specified"); } } else { throw new ApplicationException("wrong argument number"); } // output file if (string.IsNullOrEmpty(outputFile)) { outputFile = inputFile.Remove(inputFile.Length - 5); // default output file, same as input without .xrns extension } // destination format destType = destType.ToLowerInvariant(); if ((destType.Equals("mod") || destType.Equals("xm")) == false) { throw new ApplicationException("-type must be xm or mod"); } #region oldcode 2 // fine pitch value //if ((fpl < 0 || fpl > 0x10) == false) // Settings.Default.ExtraFinePitchValue = fpl; //else // throw new ApplicationException("fpl should be a number between 0 and 15"); // fine volume value //if ((fvl < 0 || fvl > 0x10) == false) // Settings.Default.ExtraFineVolumeValue = fvl; //else // throw new ApplicationException("fvl should be a number between 0 and 15"); // frequency conversion //if (convfreq) // Settings.Default.MantainOriginalSampleFreq = false; // pro tracker compatibility //if (ptmode) // Settings.Default.PTCompatibiliy = true; // volume adjust //if (adjvol) // Settings.Default.VolumeResampling = true; // bass email //if (string.IsNullOrEmpty(bassEmail) == false) // Settings.Default.BassEmail = bassEmail; // bass code //if (string.IsNullOrEmpty(bassCode) == false) // Settings.Default.BassCode = bassCode; #endregion // log file if (string.IsNullOrEmpty(outputLog) == false) { bool isValidLogPath = true; if ((string.IsNullOrEmpty(Path.GetDirectoryName(outputLog)) == false) && Directory.Exists(outputLog) == false) { isValidLogPath = false; } //if (string.IsNullOrEmpty(Path.GetFileName(outputLog)) == false) // isValidLogPath = false; if (isValidLogPath) { StreamWriter sw = new StreamWriter(outputLog); sw.AutoFlush = true; Console.SetOut(sw); } else { throw new ApplicationException("invalid log path"); } } #region old code //for (int i = 1; i < args.Length; i++) //{ // switch (args[i]) // { // case "-out": // i++; // if (args.Length >= i + 1) // { // outputFile = args[i]; // } // else // { // throw new ApplicationException("-out requires a valid filename"); // } // break; // case "-type": // i++; // if (args.Length >= i + 1) // { // if (args[i].ToLowerInvariant().Equals("xm")) // { // destType = "xm"; // } // else if (args[i].ToLowerInvariant().Equals("mod")) // { // destType = "mod"; // } // else // { // throw new ApplicationException("invalid argument: " + args[i - 1] + "; type must be xm or mod"); // } // } // else // { // throw new ApplicationException("-type must be xm or mod"); // } // break; // case "-convfreq": // Settings.Default.MantainOriginalSampleFreq = false; // break; // case "-ptmode": // Settings.Default.PTCompatibiliy = true; // break; // case "-modvol": // Settings.Default.VolumeResampling = true; // break; // case "-fpl": // i++; // if (args.Length >= i + 1) // { // int argument = int.Parse(args[i]); // if (argument < 0x10) // { // Settings.Default.ExtraFinePitchValue = argument; // } // } // else // { // throw new ApplicationException("invalid argument: " + args[i - 1] + "; fpl should be a number between 0 and 15"); // } // break; // case "-fvl": // i++; // if (args.Length >= i + 1) // { // int argument = int.Parse(args[i]); // if (argument < 0x10) // { // Settings.Default.ExtraFineVolumeValue = argument; // } // } // else // { // throw new ApplicationException("invalid argument: " + args[i - 1] + "; fvl should be a number between 0 and 15"); // } // break; // default: // throw new ApplicationException("Error: some arguments might be not correct"); // } //} #endregion if (downgrade) { XrnsManager manager = new XrnsManager(inputFile); Console.WriteLine("Loading file..."); //manager.Load(inputFile); Console.Write("Starting downgrade "); if (replaceZK) { Console.Write("and replacing ZK commands "); } Console.WriteLine("..."); try { manager.DowngradeSong(replaceZK); Console.WriteLine("Downgrade completed"); } catch (XrnsException e) { Console.WriteLine(e.Message); retcode = -1; } return(retcode); //manager.Close(); } BassWrapper.InitResources(IntPtr.Zero, bassEmail, bassCode); //MainFactory.InitResources(IntPtr.Zero, bassEmail, bassCode); /* ** Slamy: Moving the cursor like this causes problems on Mono. ** It says 'fixing "Value must be positive and below the buffer height."' ** But it doesn't seems to be necessary anyway? I'll comment it out. */ //Console.CursorTop++; Console.WriteLine("Reading xrns data..."); //MainFactory.LoadXrns(inputFile); SongDataFactory songDataFactory = new SongDataFactory(); songDataFactory.ReportProgress += ReportProgress; RenoiseSong renoiseSong = songDataFactory.ExtractRenoiseSong(inputFile); SongData songData = songDataFactory.ExtractSongData(renoiseSong, inputFile); byte[] output; IConverter converter = null; Console.Write(Environment.NewLine); Console.WriteLine("File is ok, now it's time to convert."); Console.WriteLine("{0} conversion has started... please wait ", destType); DateTime dtStart = DateTime.Now; //MainFactory.ReportProgress += new ReportProgressHandler(converter_ReportProgress); if (destType.Equals("xm")) { XmSettings settings = new XmSettings(); if (tempo == 0) { tempo = songData.InitialBPM; } if (ticks == 0) { ticks = songData.TicksPerLine; } settings.VolumeScalingMode = GetVolumeScalingMode(volumeScalingMode); settings.Tempo = tempo; settings.TicksRow = ticks; converter = new XMConverter(inputFile); converter.EventProgress += ReportProgress; ((XMConverter)converter).Settings = settings; } else { ModSettings settings = new ModSettings(); //settings.MantainOriginalSampleFreq = !convfreq; settings.ForceProTrackerCompatibility = GetProtrackerCompatibilityMode(ptmode); settings.NtscMode = ptNtsc; settings.VolumeScalingMode = GetVolumeScalingMode(volumeScalingMode); settings.PortamentoLossThreshold = portamentoLossThreshold; settings.printSettings(); if (portamentoLossThreshold < 0 || portamentoLossThreshold > 4) { throw new ApplicationException("invalid portamento loss threshold value (valid range: 0-4)"); } if (settings.VolumeScalingMode == VOLUME_SCALING_MODE.COLUMN) { throw new ApplicationException("invalid volume scaling mode for MOD"); } //settings.VolumeScaling = adjvol; converter = new ModConverter(inputFile); converter.EventProgress += ReportProgress; ((ModConverter)converter).Settings = settings; } output = converter.Convert(songData); //outputFile = Path.Combine(Path.GetDirectoryName(outputFile), Path.GetFileNameWithoutExtension(outputFile)); outputFile = System.Text.RegularExpressions.Regex.Match(outputFile, @"(?:(?!\.(mod|xm)$).)*").Value; string outputFileExt = System.Text.RegularExpressions.Regex.Match(outputFile, @"\.(mod | xm)$").Value; // add extension to output file in case user has not already specified it if (!outputFileExt.Equals("." + destType, StringComparison.CurrentCultureIgnoreCase)) { outputFile += '.' + destType; } Utility.SaveByteArrayToFile(outputFile, output); TimeSpan ts = DateTime.Now.Subtract(dtStart); Console.WriteLine("\nDone"); Console.WriteLine("Time elapsed: {0}", ts.TotalSeconds); Console.WriteLine("Output file size: {0} bytes", new FileInfo(outputFile).Length); } } catch (ApplicationException e) { Console.WriteLine(e.Message); retcode = -1; } catch (Exception e) { Console.WriteLine(e.Message); retcode = -1; } finally { //MainFactory.FreeResources(); } return(retcode); }
public Song Process(RenoiseSong project, ILog logger) { this.logger = logger; // hex lookup.. because reasons... for (int i = 0; i <= 255; i++) { hexLookUp.Add(i.ToString("X2"), (byte)i); } this.project = project; var song = new Song(); song.Tempo = (int)this.project.GlobalSongData.BeatsPerMin; song.SampleRate = 44100; secondsPerIndex = (double)song.Tempo * (double)this.project.GlobalSongData.LinesPerBeat; secondsPerIndex = 60 / secondsPerIndex; sampleRate = song.SampleRate; song.Length = GetSongLength(); var master = this.project.Tracks.Items.Where(track => track is SequencerMasterTrack).First(); trackReceives = new Dictionary <object, List <RnsReceive> >(); foreach (var projectTrack in this.project.Tracks.Items) { trackReceives.Add(projectTrack, new List <RnsReceive>()); } // send mapping foreach (var projectTrack in this.project.Tracks.Items) { string trackName = GetProp("Name", projectTrack).ToString(); object[] trackDevices = ((TrackFilterDeviceChain)GetProp("FilterDevices", projectTrack)).Devices.Items; var sends = new List <SendDevice>(); // get all send devices bool found = false; foreach (var device in trackDevices) { if (device is SendDevice) { found = true; sends.Add((SendDevice)device); } if (found && !(device is SendDevice)) { logger.WriteLine("WARNING: Track {0} has device {1} after send", trackName, device); } } foreach (var send in sends) { if (send.MuteSource && sends.IndexOf(send) != sends.Count - 1) { logger.WriteLine("WARNING: Track {0} has muted send which is not the last send in the chain", trackName); } if (send.IsActive.Value == 1 && send.SendAmount.Value > 0) { var sendTrack = GetSendTrack((int)send.DestSendTrack.Value); trackReceives[sendTrack].Add(new RnsReceive(projectTrack, 0, send.SendAmount.Value)); } else { logger.WriteLine("WARNING: Track {0} has disabled send", trackName); } } // track is not master, so find where it goes... if (projectTrack != master) { int routing = (int)GetProp("TrackRouting", projectTrack); if (routing == 0) { // routed to master if (!MutedSend(projectTrack)) // muted send so no actual output { var trackVolume = GetTrackVolume(trackDevices[0]); trackReceives[master].Add(new RnsReceive(projectTrack, 0, trackVolume)); } } else if (routing == -1) { // routed to group track if (!MutedSend(projectTrack)) // muted send so no actual output { var group = GetGroupTrack(projectTrack); var trackVolume = GetTrackVolume(trackDevices[0]); trackReceives[group].Add(new RnsReceive(projectTrack, 0, trackVolume)); } } else { // routed to specific soundcard output logger.WriteLine(string.Format("WARNING: Track {0} routing to soundcard?? WTF!", trackName)); } } } visitedTracks = new List <object>(); orderedTracks = new List <object>(); VisitTrack(master); GetInstruments(); var projectTracksToSongTracks = new Dictionary <object, Song.Track>(); foreach (var projectTrack in orderedTracks) { var track = ConvertTrack(this.project.Tracks.Items.ToList().IndexOf(projectTrack)); projectTracksToSongTracks.Add(projectTrack, track); song.Tracks.Add(track); } foreach (var kvp in projectTracksToSongTracks) { foreach (var projectReceive in trackReceives[kvp.Key]) { if (projectTracksToSongTracks.ContainsKey(projectReceive.SendingTrack)) { var receive = new Song.Receive(); receive.SendingTrackIndex = song.Tracks.IndexOf(projectTracksToSongTracks[projectReceive.SendingTrack]); receive.ReceivingChannelIndex = projectReceive.ReceivingChannelIndex; receive.Volume = (float)projectReceive.Volume; kvp.Value.Receives.Add(receive); } } } return(song); }
public RenoiseSong Process(string fileName) { var song = new RenoiseSong(); return(Process(File.ReadAllBytes(fileName))); }