Exemple #1
0
 public override void ProcessFile(OutputFile file, ConvertOptions options)
 {
     file = new OutputFile(Path.GetTempFileName(), file.Data);
     save.ProcessFile(file, options);
     dro_player.Arguments = "/c dro_player \""+file.Path+"\"";
     Process proc = Process.Start(dro_player);
     Process ctlProc = proc;
     ConsoleCancelEventHandler oncancel = (o,a) => {a.Cancel = true; ctlProc.Kill();};
     Console.CancelKeyPress += oncancel;
     try{
         int read;
         bool first = true;
         while((read = proc.StandardOutput.Read()) != -1)
         {
             if(first)
             {
                 ctlProc = GetChildProcesses(proc).FirstOrDefault() ?? proc;
                 first = false;
             }
             Console.Write((char)read);
         }
         proc.WaitForExit();
     }finally{
         Console.CancelKeyPress -= oncancel;
         if(!proc.HasExited) proc.Kill();
         File.Delete(file.Path);
     }
     Console.WriteLine();
 }
Exemple #2
0
 public override void ProcessFile(OutputFile file, ConvertOptions options)
 {
     using(StreamWriter writer = new StreamWriter(new FileStream(file.Path, FileMode.Create)))
     {
         foreach(var cmd in file.Data)
         {
             writer.WriteLine(cmd.ToString());
         }
     }
 }
Exemple #3
0
 public override void ProcessFile(OutputFile file, ConvertOptions options)
 {
     Console.WriteLine(file.Path);
     Console.WriteLine(TimeSpan.FromMilliseconds(file.Data.Sum(cmd => cmd.DelayValue)));
     Console.WriteLine("Creating WAV...");
     var song = SaveWAV.CreateSong(file.Data, SaveWAV.GetWaveform(options), options.Wave_Volume??1.0, options.Wave_Clip??false, options.Wave_Frequency??44100, options.ClickLength);
     Console.WriteLine("Playing...");
     using(var buffer = new MemoryStream())
     {
         SaveWAV.Writer.WriteWave(buffer, song);
         buffer.Position = 0;
         var player = new SoundPlayer(buffer);
         player.PlaySync();
     }
 }
Exemple #4
0
 public override void ProcessFile(OutputFile file, ConvertOptions options)
 {
     Console.WriteLine(file.Path);
     Console.WriteLine(TimeSpan.FromMilliseconds(file.Data.Sum(cmd => cmd.DelayValue)));
     Stopwatch sw = new Stopwatch();
     var rpc = file.Data;
     sw.Start();
     for(int i = 0; i < rpc.Count; i++)
     {
         var cmd = rpc[i];
         if(cmd.Type == RPCCommandType.SetCountdown || cmd.Type == RPCCommandType.ClearCountdown)
         {
             int delay = 0;
             for(int j = i+1; j < rpc.Count; j++)
             {
                 var cmd2 = rpc[j];
                 if(cmd2.Type == RPCCommandType.Delay)
                 {
                     delay += cmd2.Data;
                 }else{
                     i = j-1;
                     break;
                 }
             }
             if(cmd.Type == RPCCommandType.SetCountdown)
             {
                 int freq = 1193180/cmd.Data;
                 if(freq >= 37 && freq <= 32767 && delay > 0)
                 {
                     Console.Beep(freq, delay);
                 }else if(delay > 0)
                 {
                     Console.WriteLine("Bad frequency "+freq);
                     Thread.Sleep(delay);
                 }
             }else if(cmd.Type == RPCCommandType.ClearCountdown)
             {
                 Thread.Sleep(delay);
             }
         }else if(cmd.Type == RPCCommandType.Delay)
         {
             Thread.Sleep(cmd.Data);
         }
         Console.Write(sw.Elapsed+"\r");
     }
     sw.Stop();
     Console.WriteLine();
 }
Exemple #5
0
        public override void ProcessFile(OutputFile file, ConvertOptions options)
        {
            using(BinaryWriter writer = new BinaryWriter(new FileStream(file.Path, FileMode.Create), Encoding.ASCII))
            {
                writer.Write((byte)0x08);
                writer.Write("MONOTONE".ToCharArray());
                writer.Write(new byte[82]);
                writer.Write(new byte[]{1,1,1,2,0});
                writer.Write(Enumerable.Repeat((byte)0xFF, 255).ToArray());

                byte lastb = 0;
                foreach(var cmd in file.Data)
                {
                    switch(cmd.Type)
                    {
                        case RPCCommandType.SetCountdown:
                            double freq = LoadMDT.CountdownToFrequency(cmd.Data);
                            var bval = freq/15;
                            if(bval > 255)
                            {
                                lastb = 0;
                            }else{
                                lastb = (byte)bval;
                            }
                            break;
                        case RPCCommandType.ClearCountdown:
                            lastb = 0;
                            break;
                        case RPCCommandType.Delay:
                            for(int i = 0; i < cmd.DelayValue*60/1000.0; i++)
                            {
                                writer.Write((byte)0);
                                writer.Write(lastb);
                            }
                            break;
                    }
                }
            }
        }
Exemple #6
0
 public virtual void ProcessFile(OutputFile file, ConvertOptions options)
 {
     using(var stream = new FileStream(file.Path, FileMode.Create))
     {
         var writer = new BinaryWriter(stream);
         writer.Write(0);
         byte lastb = 0;
         foreach(var cmd in file.Data)
         {
             switch(cmd.Type)
             {
                 case RPCCommandType.SetCountdown:
                     double freq = LoadMDT.CountdownToFrequency(cmd.Data);
                     var bval = freq/15;
                     if(bval > 255)
                     {
                         lastb = 0;
                     }else{
                         lastb = (byte)bval;
                     }
                     break;
                 case RPCCommandType.ClearCountdown:
                     lastb = 0;
                     break;
                 case RPCCommandType.Delay:
                     for(int i = 0; i < cmd.DelayValue*140/1000.0; i++)
                     {
                         writer.Write(lastb);
                     }
                     break;
             }
         }
         stream.Position = 2;
         writer.Write((short)(stream.Length-4));
     }
 }
Exemple #7
0
 public abstract void ProcessFile(OutputFile file, ConvertOptions options);
Exemple #8
0
        public override void ProcessFile(OutputFile file, ConvertOptions options)
        {
            List <DROCommand> dro = new List <DROCommand>();

            if (options.MultiChannel)
            {
                for (int i = 0; i < 9; i++)
                {
                    dro.Add(new DROCommand(0x20 + oper1[i], 0x01));
                    dro.Add(new DROCommand(0x20 + oper1[i] + 3, 0x01));
                    dro.Add(new DROCommand(0x40 + oper1[i], 0x10));
                    dro.Add(new DROCommand(0x40 + oper1[i] + 3, 0x07));
                    dro.Add(new DROCommand(0x60 + oper1[i], 0xF0));
                    dro.Add(new DROCommand(0x60 + oper1[i] + 3, 0xF0));
                    dro.Add(new DROCommand(0x80 + oper1[i], 0x77));
                    dro.Add(new DROCommand(0x80 + oper1[i] + 3, 0x77));
                    dro.Add(new DROCommand(0xE0 + oper1[i], options.Waveform ?? 2));
                }
            }
            else
            {
                dro.Add(new DROCommand(0x20, 0x01));
                dro.Add(new DROCommand(0x23, 0x01));
                dro.Add(new DROCommand(0x40, 0x10));
                dro.Add(new DROCommand(0x43, 0x07));
                dro.Add(new DROCommand(0x60, 0xF0));
                dro.Add(new DROCommand(0x63, 0xF0));
                dro.Add(new DROCommand(0x80, 0x77));
                dro.Add(new DROCommand(0x83, 0x77));
                dro.Add(new DROCommand(0xE0, options.Waveform ?? 2));
            }
            if (options.DRO_PrefixCommands != null)
            {
                dro.AddRange(options.DRO_PrefixCommands);
            }

            foreach (var cmd in file.Data)
            {
                if (cmd.Channel > 8)
                {
                    throw new ArgumentException("Only 9 channels are supported.");
                }
                switch (cmd.Type)
                {
                case RPCCommandType.Delay:
                    dro.AddRange(DROCommand.Delay(cmd.Data));
                    break;

                case RPCCommandType.SetCountdown:
                    double frequency = 1193180.0 / cmd.Data;
                    int    octave    = 4;
                    while (frequency > 780.0375)                            //0x03FF * 0.7625
                    {
                        frequency /= 2;
                        octave    += 1;
                        if (octave > 7)
                        {
                            break;
                        }
                    }
                    if (octave > 7)
                    {
                        dro.Add(new DROCommand(0xB0 | cmd.Channel, 0x10));
                    }
                    else
                    {
                        int fnum = (int)(frequency / 0.7625);
                        dro.Add(new DROCommand(0xA0 | cmd.Channel, fnum & 0x00FF));
                        dro.Add(new DROCommand(0xB0 | cmd.Channel, ((fnum & 0x0300) >> 8) | 0x20 | ((octave & 7) << 2)));
                    }
                    break;

                case RPCCommandType.ClearCountdown:
                    dro.Add(new DROCommand(0xB0 | cmd.Channel, 0x10));
                    break;
                }
            }

            if (options.DRO_EndDelay > 0)
            {
                dro.AddRange(DROCommand.Delay(options.DRO_EndDelay));
            }

            if (options.DRO_Optimize)
            {
                byte?[] registers = new byte?[0xFF];
                for (int i = 0; i < dro.Count; i++)
                {
                    DROCommand cmd = dro[i];
                    if (cmd.IsOPL)
                    {
                        if (registers[cmd.OPLRegister] == cmd.OPLValue)
                        {
                            dro.RemoveAt(i);
                            i -= 1;
                        }
                        registers[cmd.OPLRegister] = cmd.OPLValue;
                    }
                }
                for (int i = 0; i < dro.Count; i++)
                {
                    DROCommand cmd = dro[i];
                    if (cmd.IsDelay)
                    {
                        if (i + 1 < dro.Count && dro[i + 1].IsDelay)
                        {
                            int delay = cmd.DelayValue + dro[i + 1].DelayValue;
                            dro[i] = DROCommand.Delay(delay).First();
                            dro.RemoveAt(i + 1);
                            i -= 1;
                        }
                    }
                }
            }

            int bytesize = dro.Sum(cmd => cmd.Length);
            int timesize = dro.Sum(cmd => cmd.DelayValue);

            using (BinaryWriter writer = new BinaryWriter(new FileStream(file.Path, FileMode.Create), Encoding.ASCII))
            {
                writer.Write("DBRAWOPL".ToCharArray());
                writer.Write((short)0);
                writer.Write((short)1);
                writer.Write(timesize);
                writer.Write(bytesize);
                writer.Write((byte)0);
                writer.Write(new byte[3]);
                foreach (var cmd in dro)
                {
                    writer.Write((byte)cmd.Register);
                    writer.Write(cmd.Data);
                }
            }
        }
Exemple #9
0
 public override void ProcessFile(OutputFile file, ConvertOptions options)
 {
     using(var stream = new FileStream(file.Path, FileMode.Create))
     {
         Writer.SampleRate = options.Wave_Frequency??44100;
         Writer.WriteWave(stream, CreateSong(file.Data, GetWaveform(options), options.Wave_Volume??1.0, options.Wave_Clip??false, options.Wave_Frequency??44100, options.ClickLength));
     }
 }
Exemple #10
0
 public abstract void ProcessFile(OutputFile file, ConvertOptions options);
Exemple #11
0
        public override void ProcessFile(OutputFile file, ConvertOptions options)
        {
            List<DROCommand> dro = new List<DROCommand>();
            if(options.MultiChannel)
            {
                for(int i = 0; i < 9; i++)
                {
                    dro.Add(new DROCommand(0x20 + oper1[i], 0x01));
                    dro.Add(new DROCommand(0x20 + oper1[i] + 3, 0x01));
                    dro.Add(new DROCommand(0x40 + oper1[i], 0x10));
                    dro.Add(new DROCommand(0x40 + oper1[i] + 3, 0x07));
                    dro.Add(new DROCommand(0x60 + oper1[i], 0xF0));
                    dro.Add(new DROCommand(0x60 + oper1[i] + 3, 0xF0));
                    dro.Add(new DROCommand(0x80 + oper1[i], 0x77));
                    dro.Add(new DROCommand(0x80 + oper1[i] + 3, 0x77));
                    dro.Add(new DROCommand(0xE0 + oper1[i], options.Waveform ?? 2));
                }
            }else{
                dro.Add(new DROCommand(0x20, 0x01));
                dro.Add(new DROCommand(0x23, 0x01));
                dro.Add(new DROCommand(0x40, 0x10));
                dro.Add(new DROCommand(0x43, 0x07));
                dro.Add(new DROCommand(0x60, 0xF0));
                dro.Add(new DROCommand(0x63, 0xF0));
                dro.Add(new DROCommand(0x80, 0x77));
                dro.Add(new DROCommand(0x83, 0x77));
                dro.Add(new DROCommand(0xE0, options.Waveform ?? 2));
            }
            if(options.DRO_PrefixCommands != null) dro.AddRange(options.DRO_PrefixCommands);

            bool informed = false;
            foreach(var cmd in file.Data)
            {
                if(cmd.Channel > 8)
                {
                    throw new ArgumentException("Only 9 channels are supported.");
                }
                switch(cmd.Type)
                {
                    case RPCCommandType.Delay:
                        if(cmd.Data == 0)
                        {
                            if(options.ClickLength != null)
                            {
                                dro.AddRange(DROCommand.Delay(Math.Max(1, (int)Math.Round(options.ClickLength.Value))));
                            }else{
                                if(!informed)
                                {
                                    Console.WriteLine("Song contains zero-length waves. Use --clicks 1 to render them as clicks.");
                                    informed = true;
                                }
                                dro.AddRange(DROCommand.Delay(cmd.Data));
                            }
                        }else{
                            dro.AddRange(DROCommand.Delay(cmd.Data));
                        }
                        break;
                    case RPCCommandType.SetCountdown:
                        double frequency = 1193180.0/cmd.Data;
                        int octave = 4;
                        while(frequency > 780.0375) //0x03FF * 0.7625
                        {
                            frequency /= 2;
                            octave += 1;
                            if(octave > 7) break;
                        }
                        if(octave > 7)
                        {
                            dro.Add(new DROCommand(0xB0 | cmd.Channel, 0x10));
                        }else{
                            int fnum = (int)(frequency/0.7625);
                            dro.Add(new DROCommand(0xA0 | cmd.Channel,  fnum & 0x00FF));
                            dro.Add(new DROCommand(0xB0 | cmd.Channel,((fnum & 0x0300) >> 8) | 0x20 | ((octave & 7) << 2)));
                        }
                        break;
                    case RPCCommandType.ClearCountdown:
                        dro.Add(new DROCommand(0xB0 | cmd.Channel, 0x10));
                        break;
                }
            }

            if(options.DRO_EndDelay > 0) dro.AddRange(DROCommand.Delay(options.DRO_EndDelay));

            if(options.Optimize)
            {
                byte?[] registers = new byte?[0xFF];
                for(int i = 0; i < dro.Count; i++)
                {
                    DROCommand cmd = dro[i];
                    if(cmd.IsOPL)
                    {
                        if(registers[cmd.OPLRegister] == cmd.OPLValue)
                        {
                            dro.RemoveAt(i);
                            i -= 1;
                        }
                        registers[cmd.OPLRegister] = cmd.OPLValue;
                    }
                }
                for(int i = 0; i < dro.Count; i++)
                {
                    DROCommand cmd = dro[i];
                    if(cmd.IsDelay)
                    {
                        if(i+1 < dro.Count && dro[i+1].IsDelay)
                        {
                            int delay = cmd.DelayValue + dro[i+1].DelayValue;
                            dro[i] = DROCommand.Delay(delay).First();
                            dro.RemoveAt(i+1);
                            i -= 1;
                        }
                    }
                }
            }

            int bytesize = dro.Sum(cmd => cmd.Length);
            int timesize = dro.Sum(cmd => cmd.DelayValue);
            using(BinaryWriter writer = new BinaryWriter(new FileStream(file.Path, FileMode.Create), Encoding.ASCII))
            {
                writer.Write("DBRAWOPL".ToCharArray());
                writer.Write((short)0);
                writer.Write((short)1);
                writer.Write(timesize);
                writer.Write(bytesize);
                writer.Write((byte)0);
                writer.Write(new byte[3]);
                foreach(var cmd in dro)
                {
                    writer.Write((byte)cmd.Register);
                    writer.Write(cmd.Data);
                }
            }
        }