Exemplo n.º 1
0
        static void Main(string[] args)
        {
            Conversion conv = new Conversion();

            string projectfilename = "Default.tcproject";

            if (args.Count() > 0)
            {
                projectfilename = args[0];
            }

            projectfilename = Path.GetFullPath(projectfilename);

            string jsonString;
            var    jsonserializeroptions = new JsonSerializerOptions
            {
                WriteIndented       = true,
                AllowTrailingCommas = true,
                ReadCommentHandling = JsonCommentHandling.Skip,
            };

            if (!File.Exists(projectfilename))
            {
                conv.Project = new TCProject();
                jsonString   = JsonSerializer.Serialize(conv.Project, jsonserializeroptions);
                File.WriteAllText(projectfilename, jsonString);
                Console.WriteLine("Default project file written. It will be good for you. " + projectfilename);
                Environment.Exit(0);
            }
            Directory.SetCurrentDirectory(Path.GetDirectoryName(projectfilename));

            jsonString   = File.ReadAllText(projectfilename);
            conv.Project = JsonSerializer.Deserialize <TCProject>(jsonString, jsonserializeroptions);

            conv.XM = new XMRead(conv.Project.TrackFile);
            conv.XM.Open();

            conv.ITF = conv.XM.ToITF();


            Console.WindowWidth  = 200;
            Console.WindowHeight = 60;

            conv.XM.Header.ToConsole();


            int instrnr = 1;

            foreach (Instrument instrument in conv.Project.YM2151Instruments)
            {
                YM2151Instrument instr = new YM2151Instrument();
                instr.ReadFromDMP(instrument.DMPFile);
                conv.DefinedInstruments[instrnr] = instr;
                instrnr++;
                Console.WriteLine("Instrument " + instrnr);
                instr.ToConsole();
            }

            Console.WriteLine("Patterns:");
            for (int i = 0; i < conv.XM.Patterns.Length; i++)
            {
                XMPattern pattern = conv.XM.Patterns[i];
                Console.WriteLine(i + ": " + pattern.LenghtOfPatternHeader + " " + pattern.PatternPackType + " " + pattern.NumberOfRows + " " + pattern.SizeOfPatternData);
            }

            Console.WriteLine("Instruments:");
            for (int i = 0; i < conv.XM.Instruments.Length; i++)
            {
                XMInstrument instrument = conv.XM.Instruments[i];
                Console.WriteLine(i + ": " + instrument.NumberOfSamples + " " + instrument.InstrumentName + " " + instrument.Samples[0].NameOfSample + " " + instrument.nextinstrumentofset);
            }

            List <XMNote> allnotes = new List <XMNote>();

            foreach (var item in conv.XM.Header.PatternOrderTable)
            {
                XMPattern pattern = conv.XM.Patterns[item];
                if (pattern.PatArr != null)
                {
                    foreach (var arre in pattern.PatArr)
                    {
                        if (arre == null)
                        {
                            Console.WriteLine("NULL");
                        }
                        allnotes.Add(arre);
                    }
                }
            }


            Console.WriteLine("Used effects:");
            var effects = allnotes.Select(x => x.Effect).Distinct().OrderBy(x => x).ToList();

            foreach (var item in effects)
            {
                Console.WriteLine(item.ToString("X2"));
            }


            ////foreach (var item in conv.XM.Header.PatternOrderTable)
            ////{
            ////    conv.XM.Patterns[item].PatternToConsole();
            ////    break;
            ////}


            ////for (int i = 0; i < 8; i++)
            //int i = 0;
            //{
            //    var e = instr.ToControlBytes(i);
            //    foreach (var item in e)
            //    {
            //        bytes.Add(item.Key);
            //        bytes.Add(item.Value);
            //    }
            //}


            //XMNote note = new XMNote() { octave = 3, note = 0 };
            //note.NoteIntoBytes(bytes, 0, 0b01100000);
            //note.note = 4;
            //note.NoteIntoBytes(bytes, 0, 0b00011000);

            conv.CurrentBPM        = conv.ITF.BeatPerMinute;
            conv.CurrentTickPerRow = conv.ITF.TickPerRow;
            if (conv.Project.OverrideRowPerBeat.HasValue)
            {
                conv.CurrentRowPerBeat = conv.Project.OverrideRowPerBeat.Value;
            }

            //Start pause
            conv.OBs.AddRange(new byte[] { 0, 60 });


            int patterncounter = 0;

            bool[] channelson = { true, true, true, true, true, true, true, true };
            foreach (var item in conv.ITF.PlayOrder)
            {
                int?FromRow = null;
                int?ToRow   = null;

                if (conv.Project.ConvertFrom != null && conv.Project.ConvertFrom.Track.HasValue)
                {
                    if (conv.Project.ConvertFrom.Track.Value == patterncounter)
                    {
                        FromRow = conv.Project.ConvertFrom.Row;
                    }
                    if (conv.Project.ConvertFrom.Track.Value > patterncounter)
                    {
                        patterncounter++;
                        continue;
                    }
                }

                if (conv.Project.ConvertTo != null && conv.Project.ConvertTo.Track.HasValue)
                {
                    if (conv.Project.ConvertTo.Track.Value == patterncounter)
                    {
                        ToRow = conv.Project.ConvertTo.Row;
                    }
                    if (conv.Project.ConvertTo.Track.Value < patterncounter)
                    {
                        patterncounter++;
                        continue;
                    }
                }

                conv.OBs.AddRange(item.PatternToBytes(conv, channelson, FromRow, ToRow));
                //conv.XM.Patterns[item].PatternToConsole();
                patterncounter++;
            }

            if (conv.Project.OutputDirectory != null)
            {
                Directory.SetCurrentDirectory(conv.Project.OutputDirectory);
            }

            //Trailing pause
            conv.OBs.AddRange(new byte[] { 0, 60 });

            CX16BasicWriter.ToFile(conv.OBs);
            DumbBinWriter.ToFile(conv.OBs);
            DMFWriter.ToDMF(conv);
            VGMWriter.ToFile(conv.OBs);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            //VGMRead reader = new VGMRead(@"C:\Users\mpathy\Desktop\TrackerMuzax\vgzs\03 Water.vgm");
            VGMRead reader = new VGMRead(@"C:\Users\mpathy\Desktop\TrackerMuzax\vgzs\06 Chani's Eyes.vgm");

            //VGMRead reader = new VGMRead(@"C:\Users\mpathy\Desktop\TrackerMuzax\vgzs\07 Sign of the Worm.vgm");
            reader.Open();

            //Statistics.VGMWaitTotal(reader);
            //Statistics.YM3812WaveformStatistics(reader);
            //Statistics.YM3812Notes(reader);
            //Visulaize.ChannelStats(reader);

            double waittickcorrection = 0;
            double x16tickinmillisec  = 1000 / 60;

            YM3812 ym3812 = new YM3812();
            YM2151 ym2151 = new YM2151();

            List <byte> outbytes = new List <byte>();

            //Start pause.
            //outbytes.AddRange(new byte[] { 0, 60 });

            ym2151.Reset();
            ym2151.NextTick();
            ym3812.NextTick();
            foreach (var command in reader.VGMCommands)
            {
                if (command is YM3812Command)
                {
                    ym3812.ConsumeCommand((YM3812Command)command);
                }
                if (command is VGMwait || command is VGMendofsounddata)
                {
                    ConvertYM3812stateToYM2151state(ym3812, ym2151);

                    outbytes.AddRange(ym2151.GetChangedRegisters());
                    outbytes.AddRange(ConvertYM3812KeyOnStateToYM2151KeyOnCommands(ym3812));


                    if (command is VGMwait)
                    {
                        var waitmillisecs      = ((VGMwait)command).waitsamples / 44.100;
                        var unroundedwaitticks = waitmillisecs / x16tickinmillisec;
                        unroundedwaitticks += waittickcorrection;
                        var waitticks = Math.Round(unroundedwaitticks);
                        waittickcorrection = unroundedwaitticks - waitticks;

                        if (waitticks != 0)
                        {
                            while (waitticks > 0)
                            {
                                outbytes.Add(0);
                                if (waitticks > 255)
                                {
                                    outbytes.Add(255);
                                }
                                else
                                {
                                    outbytes.Add((byte)waitticks);
                                }
                                waitticks -= 255;
                            }
                        }
                    }

                    ym2151.NextTick();
                    ym3812.NextTick();
                }
            }

            //Trailing pause
            //outbytes.AddRange(new byte[] { 0, 60 });

            Directory.SetCurrentDirectory(@"C:\Users\mpathy\Source\Repos\TrackConv\Player");
            CX16BasicWriter.ToFile(outbytes);
            DumbBinWriter.ToFile(outbytes);
            VGMWriter.ToFile(outbytes);
        }