예제 #1
0
 protected override void OnClosing(CancelEventArgs e)
 {
     player.Dispose();
     WindowPositionUtils.UpdateBounds(PropertyItem.MainWindowPos, new Point()
     {
         X = Left, Y = Top
     });
     if (soundBoardForm != null)
     {
         soundBoardForm.Close();
     }
     if (playListForm != null)
     {
         playListForm.Close();
     }
     if (trackSelectionForm != null)
     {
         trackSelectionForm.Close();
     }
     if (liveInputForm != null)
     {
         liveInputForm.Close();
     }
     ConfigManager.SaveConfig();
     base.OnClosing(e);
 }
예제 #2
0
 public void PlaySimple()
 {
     var stream = GetType ().Assembly.GetManifestResourceStream ("Commons.Music.Midi.Tests.Resources.testmidi.mid");
     var vt = new VirtualMidiTimeManager ();
     var player = new MidiPlayer (SmfMusic.Read (stream), MidiAccessManager.Empty, vt);
     player.PlayAsync ();
     vt.AdvanceBy (10000);
     player.PauseAsync ();
     player.Dispose ();
 }
예제 #3
0
        public void PlayPortMidi()
        {
            var stream = GetType().Assembly.GetManifestResourceStream("Commons.Music.Midi.Tests.Resources.testmidi.mid");
            var vt     = new AlmostVirtualMidiTimeManager();
            var player = new MidiPlayer(MidiMusic.Read(stream), new PortMidi.PortMidiAccess(), vt);

            player.PlayAsync();
            vt.AdvanceBy(10000);
            player.PauseAsync();
            player.Dispose();
        }
예제 #4
0
 public void Stop()
 {
     try
     {
         if (player is MidiPlayer)
         {
             player.PauseAsync();
         }
     }
     catch (Exception)
     {
     }
     finally
     {
         player.Dispose();
         player = null;
     }
 }
예제 #5
0
 private void StopPlayer()
 {
     if (currentplayer == null)
     {
         return;
     }
     if (isStopping)
     {
         // spin wait until stopped
         while (isStopping)
         {
             Thread.Sleep(100);
         }
     }
     else
     {
         isStopping = true;
         currentplayer.Stop();
         // spin wait until stopped
         while (currentplayer.State != PlayerState.Stopped)
         {
             Thread.Sleep(100);
         }
         currentplayer.EventReceived          -= player_EventReceived;
         currentplayer.PlaybackCompletedToEnd -= player_Finished;
         jukebox.Current.Progress              = 0d;
         jukebox.Current.CurrentTime           = TimeSpan.FromMilliseconds(0);
         jukebox.Current.RemainingTime         = TimeSpan.FromMilliseconds(jukebox.Current.TotalTime);
         jukebox.Current.State = States.Stopped;
         currentplayer.Dispose();
         outputDevice.Dispose();
         outputDevice  = null;
         currentplayer = null;
         isStopping    = false;
     }
 }
        public static int Main(string [] args)
        {
            var  apiProviderSpec = args.FirstOrDefault(a => a.StartsWith("--provider:", StringComparison.Ordinal));
            Type apiType         = null;

            if (apiProviderSpec != null)
            {
                apiType = Type.GetType(apiProviderSpec.Substring("--provider:".Length));
                if (apiType == null)
                {
                    ShowHelp();
                    Console.Error.WriteLine();
                    Console.Error.WriteLine(apiProviderSpec + " didn't work.");
                    Console.Error.WriteLine();
                    return(-1);
                }
                Console.Error.WriteLine("Using MidiAccess '{0}'", apiType.AssemblyQualifiedName);
            }
            var api = apiProviderSpec != null ?
                      (IMidiAccess)Activator.CreateInstance(apiType) :
                      MidiAccessManager.Default;
            var  output     = api.Outputs.LastOrDefault();
            var  files      = new List <string> ();
            bool diagnostic = false;

            foreach (var arg in args)
            {
                if (arg == apiProviderSpec)
                {
                    continue;
                }
                if (arg == "--help")
                {
                    ShowHelp();
                    return(0);
                }
                else if (arg == "--verbose")
                {
                    diagnostic = true;
                }
                else if (arg.StartsWith("--device:", StringComparison.Ordinal))
                {
                    output = api.Outputs.FirstOrDefault(o => o.Id == arg.Substring(9));
                    if (output == null)
                    {
                        ShowHelp();
                        Console.WriteLine();
                        Console.WriteLine("Invalid MIDI output device ID.");
                        Console.Error.WriteLine();
                        return(-2);
                    }
                }
                else
                {
                    files.Add(arg);
                }
            }
            if (!files.Any())
            {
                ShowHelp();
                return(0);
            }

            var  wh   = new ManualResetEvent(false);
            bool loop = true;

            foreach (var arg in files)
            {
                var parser = new SmfReader();
                parser.Read(File.OpenRead(arg));
                var            player = new MidiPlayer(parser.Music, api.OpenOutputAsync(output.Id).Result);
                DateTimeOffset start  = DateTimeOffset.Now;
                if (diagnostic)
                {
                    player.EventReceived += e => {
                        string type = null;
                        switch (e.EventType)
                        {
                        case MidiEvent.NoteOn: type = "NOn"; break;

                        case MidiEvent.NoteOff: type = "NOff"; break;

                        case MidiEvent.PAf: type = "PAf"; break;

                        case MidiEvent.CC: type = "CC"; break;

                        case MidiEvent.Program: type = "@"; break;

                        case MidiEvent.CAf: type = "CAf"; break;

                        case MidiEvent.Pitch: type = "P"; break;

                        case MidiEvent.SysEx1: type = "SysEX"; break;

                        case MidiEvent.SysEx2: type = "SysEX2"; break;

                        case MidiEvent.Meta: type = "META"; break;
                        }
                        Console.WriteLine("{0:06} {1:D02} {2} {3}", (DateTimeOffset.Now - start).TotalMilliseconds, e.Channel, type, e);
                    }
                }
                ;
                player.Finished += delegate {
                    loop = false;
                    wh.Set();
                };

                new Task(() => {
                    Console.WriteLine("empty line to quit, P to pause and resume");
                    while (loop)
                    {
                        string line = Console.ReadLine();
                        if (line == "P")
                        {
                            if (player.State == PlayerState.Playing)
                            {
                                player.PauseAsync();
                            }
                            else
                            {
                                player.PlayAsync();
                            }
                        }
                        else if (line == "")
                        {
                            loop = false;
                            wh.Set();
                            player.Dispose();
                            break;
                        }
                        else
                        {
                            Console.WriteLine("what do you mean by '{0}' ?", line);
                        }
                    }
                }).Start();

                //player.StartLoop ();
                player.PlayAsync();
                while (loop)
                {
                    wh.WaitOne();
                }
                player.PauseAsync();
            }
            return(0);
        }
    }
예제 #7
0
 protected override void Unsubscribed()
 {
     _player?.Dispose();
     _player = null;
 }
예제 #8
0
        static void Main(string[] args)
        {
            var    access          = MidiAccessManager.Default;
            var    output          = access.OpenOutputAsync(access.Outputs.Last().Id).Result;
            var    music           = MidiMusic.Read(System.IO.File.OpenRead("../../../midi/avengers.mid"));
            var    player          = new MidiPlayer(music, output);
            int    HowHardPressed  = 0;
            string StrengthOfPress = "";

            player.PlayAsync();

            player.Dispose();



            if (access.Inputs.Count() > 0)
            {
                var    input = access.OpenInputAsync(access.Inputs.Last().Id).Result;
                byte[] data  = null;
                input.MessageReceived += (o, e) =>
                {
                    data = new byte[e.Length];
                    Array.Copy(e.Data, e.Start, data, 0, e.Length);



                    if (e.Data[1] != 0 && e.Data[0] == 144)
                    {
                        var    note       = e.Data[1] % 12 + 1;
                        string noteString = "N/A";
                        switch (note)
                        {
                        case 1:
                            noteString = "C";
                            break;

                        case 2:
                            noteString = "C#/D-";
                            break;

                        case 3:
                            noteString = "D";
                            break;

                        case 4:
                            noteString = "D#/E-";
                            break;

                        case 5:
                            noteString = "E";
                            break;

                        case 6:
                            noteString = "F";
                            break;

                        case 7:
                            noteString = "F#/G-";
                            break;

                        case 8:
                            noteString = "G";
                            break;

                        case 9:
                            noteString = "G#/A-";
                            break;

                        case 10:
                            noteString = "A";
                            break;

                        case 11:
                            noteString = "A#/B-";
                            break;

                        case 12:
                            noteString = "B";
                            break;

                        default:
                            noteString = "N/A";
                            break;
                        }
                        int octave = e.Data[1] / 12;
                        if (e.Data[1] != 0 && e.Data[0] != 144)
                        {
                            Console.Write("Not A NOTE?!?!?!?!?!?!?!??!?!!?!?");
                            Console.Write($"Note Played: {noteString}\t Octave Played: {octave.ToString()}\t");
                            Console.Write($"Data[0]: {e.Data[0]}\t");
                            Console.Write($"Note #: {e.Data[1]}\t");
                        }
                        else
                        {
                            /*
                             *
                             *
                             * Console.Write($"Note Played: {noteString}\t Octave Played: {octave.ToString()}\t");
                             * Console.Write($"Data[0]: {e.Data[0]}\t");
                             * Console.Write($"Note #: {e.Data[1]}\t");
                             * Console.WriteLine($"Data[2]: {e.Data[2]}");
                             */
                            HowHardPressed = e.Data[2];
                            if (HowHardPressed < 1)
                            {
                                StrengthOfPress = "StoppedPressing";
                            }
                            if (HowHardPressed > 0)
                            {
                                StrengthOfPress = "Barely";
                            }
                            if (HowHardPressed > 30)
                            {
                                StrengthOfPress = "Softly";
                            }
                            if (HowHardPressed > 55)
                            {
                                StrengthOfPress = "a healthy ammount";
                            }
                            if (HowHardPressed > 80)
                            {
                                StrengthOfPress = "Hard";
                            }
                            if (HowHardPressed > 110)
                            {
                                StrengthOfPress = "Jesus Why ?!?!";
                            }
                            if (HowHardPressed != 0)
                            {
                                Console.WriteLine("You played: " + noteString + " " + octave.ToString() + "th octave " + StrengthOfPress);
                            }
                        }
                    }
                };
            }
            while (true)
            {
                ;
            }
        }
예제 #9
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.Main);

            FindViewById <Button> (Resource.Id.openFreeStylePad).Click += delegate {
                this.StartActivity(new Intent(this, typeof(RhythmPadActivity)));
            };

            var  playChordButton = FindViewById <Button> (Resource.Id.playChord);
            bool noteOn          = false;

            if (Android.OS.Build.VERSION.SdkInt < BuildVersionCodes.M)
            {
                playChordButton.Enabled = false;                 // MIDI API not supported.
            }
            playChordButton.Click += delegate {
                //var midiService = this.GetSystemService (MidiService).JavaCast<MidiManager> ();
                //var devs = midiService.GetDevices ();

                if (recv == null)
                {
                    recv = new FluidsynthMidiReceiver(this);
                    recv.OnSend(new Byte [] { 0xB0, 7, 127 }, 0, 3, 0);
                    recv.OnSend(new Byte [] { 0xB0, 11, 127 }, 0, 3, 0);
                    recv.OnSend(new Byte [] { 0xC0, 30 }, 0, 2, 0);
                }
                if (noteOn)
                {
                    recv.OnSend(new Byte [] { 0x80, 0x30, 0x78 }, 0, 3, 0);
                    recv.OnSend(new Byte [] { 0x80, 0x39, 0x78 }, 0, 3, 0);
                }
                else
                {
                    recv.OnSend(new Byte [] { 0x90, 0x30, 0x60 }, 0, 3, 0);
                    recv.OnSend(new Byte [] { 0x90, 0x39, 0x60 }, 0, 3, 0);
                }
                noteOn = !noteOn;
                playChordButton.Text = noteOn ? "playing" : "Test Android MIDI API";
            };

            var songFileOrUrlTextEdit = FindViewById <EditText> (Resource.Id.songFileNameOrUrlEditText);
            var playSongButton        = FindViewById <Button> (Resource.Id.playSong);

            playSongButton.Click += delegate {
                if (player == null || player.State == PlayerState.Paused || player.State == PlayerState.Stopped)
                {
                    if (player == null)
                    {
                        string song = songFileOrUrlTextEdit.Text;
                        song = string.IsNullOrEmpty(song) ? "escape.mid" : song;
                        // if empty, play some song from asset.
                        StartNewSong(GetSongData(song));
                    }
                    playSongButton.Text = "playing...";
                    player.PlayAsync();
                }
                else
                {
                    playSongButton.Text = "Play song";
                    player.PauseAsync();
                    player.Dispose();
                    player = null;
                }
            };

            var mmlEditText = FindViewById <EditText> (Resource.Id.editText);

            mmlEditText.Text = new StreamReader(Assets.Open("wish.mml")).ReadToEnd();
            var playMmlButton = FindViewById <Button> (Resource.Id.playMML);

            playMmlButton.Click += delegate {
                if (player == null)
                {
                    MidiMusic song;
                    try {
                        song = CompileMmlToSong(mmlEditText.Text);
                    } catch (MmlException ex) {
                        Log.Error("FluidsynthPlayground", ex.ToString());
                        Toast.MakeText(this, ex.Message, ToastLength.Long).Show();
                        return;
                    }

                    StartNewSong(song);

                    playMmlButton.Text = "playing...";
                }
                else
                {
                    playMmlButton.Text = "Play MML";
                    player.PauseAsync();
                    player.Dispose();
                    player = null;
                }
            };

            // Mount OBBs at bootstrap.
            MidiState.Instance.MountObbs(this);
        }