public static void Main(string [] args)
        {
            var reader = new SmfReader (File.OpenRead (args [0]));
            reader.Parse ();

            var player = new WebMidiPlayer (new Uri ("http://localhost:9090"), reader.Music);
            player.PlayAsync ();
            Console.WriteLine ("Type [CR] to stop...");
            Console.ReadLine ();
            player.Dispose ();
        }
Beispiel #2
0
        public static void Main(string [] args)
        {
            int outdev = MidiDeviceManager.DefaultOutputDeviceID;
            var files = new List<string> ();
            foreach (var arg in args) {
                if (arg.StartsWith ("--device:")) {
                    if (!int.TryParse (arg.Substring (9), out outdev)) {
                        Console.WriteLine ("Specify device ID: ");
                        foreach (var dev in MidiDeviceManager.AllDevices)
                            if (dev.IsOutput)
                                Console.WriteLine ("{0}: {1}", dev.ID, dev.Name);
                        return;
                    }
                }
                else
                    files.Add (arg);
            }
            var output = MidiDeviceManager.OpenOutput (outdev);

            foreach (var arg in files) {
                var parser = new SmfReader (File.OpenRead (arg));
                parser.Parse ();
                var player = new PortMidiPlayer (output, parser.Music);
                player.StartLoop ();
                player.PlayAsync ();
                Console.WriteLine ("empty line to quit, P to pause and resume");
                while (true) {
                    string line = Console.ReadLine ();
                    if (line == "P") {
                        if (player.State == PlayerState.Playing)
                            player.PauseAsync ();
                        else
                            player.PlayAsync ();
                    }
                    else if (line == "") {
                        player.Dispose ();
                        break;
                    }
                    else
                        Console.WriteLine ("what do you mean by '{0}' ?", line);
                }
            }
        }
Beispiel #3
0
        public void LoadFile(FileInfo filename, Stream stream)
        {
            Stop ();
            var reader = new SmfReader (stream);
            reader.Parse ();
            Music = reader.Music;
            #if Moonlight
            player = new MidiPlayer (Music);
            #else
            player = new PortMidiPlayer (output, Music);
            #endif
            player.Finished += delegate { disp.BeginInvoke (() => StopViews ()); };
            registers = new MidiMachine ();
            spectrum_analyzer_panel.Registers = registers;
            player.MessageReceived += delegate (SmfMessage m) {
                registers.ProcessMessage (m);
            };
            registers.MessageReceived += delegate (SmfMessage m) {
                disp.BeginInvoke (() => HandleSmfMessage (m));
            };

            play_time_status_panel.TotalTime = player.GetTotalPlayTimeMilliseconds ();
            player.StartLoop ();
            Console.WriteLine ("Player loop started");
        }
 internal void LoadFileAsync(FileInfo file)
 {
     FileInfo prevfile = midifile;
     if (file == prevfile || file == null)
         return;
     midifile = file;
     new Thread ((ThreadStart) delegate {
         try {
             DrawCommon ("Loading " + midifile.Name);
             UpdateView();
             jetfile = midifile;
             using (var fs = File.OpenRead(midifile.FullName))
             {
                 SmfReader r = new SmfReader(fs);
                 r.Parse();
                 smf_music = r.Music;
                 smf_music = SmfTrackMerger.Merge(smf_music);
                 DrawCommon("Loaded");
             }
         } catch (SmfParserException ex) {
             DrawCommon ("Parse error " + ex);
         } catch (IOException ex) {
             DrawCommon ("I/O error " + ex);
         }
     }).Start();
 }