Inheritance: MonoBehaviour
        public async void PlaySingleNote()
        {
            try
            {
                if (!IsPlaying)
                {
                    IsPlaying = true;
                    FreePlayViewModel viewModel = (FreePlayViewModel)PageController.GetViewModel().CurrentPage.DataContext;
                    if (CurrentNote == NOTES.Length - 1)
                    {
                        CurrentNote = 0;
                        viewModel.CurrentNoteNumber = CurrentNote;
                    }
                    else
                    {
                        CurrentNote += 1;
                        viewModel.CurrentNoteNumber = CurrentNote;
                    }
                    viewModel.CurrentNoteNumber = CurrentNote;
                    SetPressedButtonColor();
                    MidiPlayer.Play(new NoteOn(0, 0, NOTES[CurrentNote], volume));
                    await Task.Factory.StartNew(() =>
                    {
                        Thread.Sleep(150);
                    });

                    SetOriginalButtonColor();
                    MidiPlayer.Play(new NoteOff(0, 0, NOTES[CurrentNote], volume));
                    IsPlaying = false;
                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }
Example #2
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // TODO: Add your initialization logic here

            graphics.PreferredBackBufferWidth  = this.windowWidth;
            graphics.PreferredBackBufferHeight = this.windowHeight;
            graphics.ApplyChanges();


            base.Initialize();

            player = new Player(playerTexture, new Vector2(widthMiddle, windowHeight - 50), new Rectangle(0, (int)(windowHeight * 0.66f), windowWidth, (int)(windowHeight - windowHeight * 0.66f)));

            var access = MidiAccessManager.Default;
            var output = access.OpenOutputAsync(access.Outputs.Last().Id).Result;

            midiMusic = MidiMusic.Read(System.IO.File.OpenRead("midiFiles/something_doin'_(nc)smythe.mid"));
            MidiAnalyser midiAnalyser = new MidiAnalyser();

            midiAnalyser.analyseMidi(midiMusic);

            noteManager = new NoteManager(new GameObject(ballTexture, new Vector2(this.widthMiddle, 0)), spawnArc, midiAnalyser, widthMiddle, 200, 800);

            midiPlayer = new MidiPlayer(midiMusic, output);
            midiPlayer.EventReceived += (MidiEvent midiEvent) => {
                if (midiEvent.EventType == MidiEvent.NoteOn)
                {
                    noteManager.addNote(midiEvent);
                }
            };
            midiPlayer.PlayAsync();
        }
Example #3
0
 public PianoRollModel()
 {
     _notesByKeys = GetNotesByKeysFromDB();
     MidiPlayer.OpenMidi();//Iniciem el objecte MIDI
     volume = 63;
     MidiPlayer.Play(new ProgramChange(0, 0, generalInstrument));
 }
        public async void PlayNOTES()
        {
            try
            {
                IsPlaying = true;
                FreePlayViewModel viewModel = (FreePlayViewModel)PageController.GetViewModel().CurrentPage.DataContext;
                while (IsPlaying)
                {
                    volume = PageController.GetPianoRollModel().volume; //получаем текущее значение громкости
                    SetPressedButtonColor();                            //меняем цвет кнопки
                    MidiPlayer.Play(new NoteOn(0, 0, NOTES[CurrentNote], volume));
                    await Task.Factory.StartNew(() =>
                    {
                        try { Thread.Sleep(Convert.ToInt32(DURATIONS[CurrentNote])); }
                        catch { Thread.Sleep(250); }
                    });

                    SetOriginalButtonColor();//возвращаем цвет
                    MidiPlayer.Play(new NoteOff(0, 0, NOTES[CurrentNote], volume));
                    CurrentNote = CurrentNote == NOTES.Length - 1 ? 0 : CurrentNote += 1;
                    viewModel.CurrentNoteNumber = CurrentNote;
                }
            }
            catch (Exception ex) { IsPlaying = false; MessageBox.Show(ex.Message); }
        }
Example #5
0
        public PartitionsForm(TrackSelectionManager tsm, MidiPlayer player)
        {
            this.tsm    = tsm;
            this.player = player;
            InitializeComponent();
            this.FormClosing            += PartitionsForm_FormClosing1;
            listBoxPartitions.MouseMove += ListBoxPartitions_MouseMove;

            if (!LuteBotForm.IsLuteModInstalled())
            {
                var popup = new PopupForm("Install LuteMod", "Would you like to update/install LuteMod?", "LuteMod is a Mordhau Mod that lets you manage your songs in game and move freely, and play duets with lute and flute\n\nLuteMod was not detected as installed, or an old version was detected\n\nThanks to Monty for LuteMod, and cswic for the autoloader\n\nFor more information, see:",
                                          new Dictionary <string, string>()
                {
                    { "What is LuteMod", "https://mordhau-bards-guild.fandom.com/wiki/LuteMod" },
                    { "LuteMod mod.io page", "https://mordhau.mod.io/lutemod" },
                    { "Autoloader mod.io page", "https://mordhau.mod.io/clientside-mod-autoloader" },
                    { "Flute and Duets", "https://mordhau-bards-guild.fandom.com/wiki/LuteMod#Flute_and_Duets" },
                    { "The Bard's Guild Discord", "https://discord.gg/4xnJVuz" },
                }, MessageBoxButtons.YesNo);
                popup.ShowDialog(this);
                if (popup.DialogResult == DialogResult.Yes)
                {
                    LuteBotForm.InstallLuteMod();
                }
                else
                {
                    Hide();
                }
            }
            RefreshPartitionList();
        }
Example #6
0
        private static void StopButton_Click(object sender, EventArgs e)
        {
            Form.Timer.Stop();
            Timer.Change(Timeout.Infinite, 10);

            SongPlayer.Stop();
            MidiPlayer.Stop();
        }
Example #7
0
 public BaloonManager()
 {
     randomSound        = new RandomFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Sounds"), "*.mp3");
     noteTimer.Tick    += NoteTimerTick;
     noteTimer.Interval = new TimeSpan(0, 0, 0, 0, 300);
     MidiPlayer.OpenMidi();
     MidiPlayer.Play(new ProgramChange(0, 1, GeneralMidiInstruments.PanFlute));
 }
Example #8
0
 //Passem una tecla, i fa servir el diccionari per passar-la a nota, per exemple Q => C4
 private void tocarNota(string tecla)
 {
     if (!tecles.Contains(tecla))
     {
         tecles.Add(tecla);
         MidiPlayer.Play(new NoteOn(0, canal, tecla_notes[tecla], volum));
     }
 }
Example #9
0
 public SettingsForm(MidiPlayer player, LuteBotForm mainForm)
 {
     InitializeComponent();
     this.player   = player;
     this.mainForm = mainForm;
     SetVersion();
     InitSettings();
 }
Example #10
0
 static void OpenMidi()
 {
     if (notesPlayed == null)
     {
         MidiPlayer.OpenMidi();
         notesPlayed = new List <string>();
     }
 }
 private void PlayButtonClick(object sender, RoutedEventArgs e)
 {
     foreach (Note note in Music)
     {
         MidiPlayer.Play(note.Tone);
         System.Threading.Thread.Sleep(note.Tempo);
     }
 }
Example #12
0
 private void soltarNota(string tecla)
 {
     if (tecles.Contains(tecla))
     {
         tecles.Remove(tecla);
         MidiPlayer.Play(new NoteOff(0, canal, tecla_notes[tecla], volum));
     }
 }
Example #13
0
 public Form1()
 {
     InitializeComponent();
     contour = new Bitmap(800, 423);
     noteLines.Add(new Stave(noteLines.Count + 1, height + 50));
     MidiPlayer.OpenMidi();
     paintNotation();
 }
Example #14
0
 private void воспроизвестиToolStripMenuItem_Click(object sender, EventArgs e)
 {
     for (int i = 0; i < notes.Count; i++)
     {
         MidiPlayer.Play(new NoteOn(0, 1, notes[i].note, 127));
         Thread.Sleep(1000 / notes[i].duration);
         MidiPlayer.Play(new NoteOff(0, 1, notes[i].note, 127));
     }
 }
Example #15
0
 void StartNewSong(MidiMusic music)
 {
     if (player != null)
     {
         player.Dispose();
     }
     player = new MidiPlayer(music, MidiState.Instance.GetMidiOutput(this));
     player.PlayAsync();
 }
Example #16
0
        public Form1()
        {
            InitializeComponent();

            Scan1();
            InitializeMidiInstrumentsCombo();
            InitializeDataGridView();
            MidiPlayer.OpenMidi();
        }
Example #17
0
        private static void Timer_Elapsed(object state)
        {
            Timer.Change(Timeout.Infinite, 10);

            SongPlayer.Update();
            MidiPlayer.Update();

            Timer.Change(10, 10);
        }
Example #18
0
 public override void OnInspectorGUI()
 {
     midiPlayer = (MidiPlayer)target;
     serializedObject.Update();
     ShowKeyboard();
     EditorGUILayout.PropertyField(serializedObject.FindProperty("octave"));
     EditorGUILayout.PropertyField(serializedObject.FindProperty("voices"), true);
     serializedObject.ApplyModifiedProperties();
 }
Example #19
0
 public static void sound(string note)
 {
     OpenMidi();
     MidiPlayer.Play(new NoteOn(0, 1, note, 100));
     if (!notesPlayed.Contains(note))
     {
         notesPlayed.Add(note);
     }
 }
Example #20
0
        private static void PlayButton_Click(object sender, EventArgs e)
        {
            //Form.SongLabel.Text = SongReader.Position.ToString("X4");
            Form.Timer.Start();

            MidiPlayer.Start();
            SongPlayer.Play();

            Timer.Change(0, 10);
        }
Example #21
0
 /// <summary>
 /// Execute start up tasks
 /// </summary>
 /// <param name="sender">object sending the event</param>
 /// <param name="e">event arguments</param>
 private void MainWindow_Loaded(object sender, RoutedEventArgs e)
 {
     if (this.bodyFrameReader != null)
     {
         this.bodyFrameReader.FrameArrived += this.Reader_FrameArrived;
     }
     midi = new MidiPlayer();
     midi.load("mario.mid");
     midi.play();
 }
Example #22
0
        private void BlackKey_MouseDown(object sender, MouseEventArgs e)
        {
            BlackPianoKey key = (BlackPianoKey)sender;

            noteValue = Note.ConvertCodeToNotation(Convert.ToInt32(key.Tag));
            MidiPlayer.Play(new ProgramChange(0, 1, GeneralMidiInstruments.AcousticGrand));
            MidiPlayer.Play(new NoteOn(0, 1, noteValue, 127));
            timer.Reset();
            timer.Start();
        }
Example #23
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 ();
 }
Example #24
0
        private void Guitar_StringMouseDown(object sender, GuitarFret.GuitarEventArgs e)
        {
            GuitarFret fret = (GuitarFret)sender;

            noteValue = Note.ConvertCodeToNotation(fret.GetCode(e.StringNumber));
            timer.Reset();
            MidiPlayer.Play(new ProgramChange(0, 1, GeneralMidiInstruments.CleanElectricGuitar));
            MidiPlayer.Play(new NoteOn(0, 1, noteValue, 127));
            timer.Start();
        }
Example #25
0
        public void StopPianoKeyByKey(string key)
        {
            string value;

            if (_notesByKeys.TryGetValue(key, out value))
            {
                pressedNotes.Remove(value);
                MidiPlayer.Play(new NoteOff(0, 0, value, volume));
            }
        }
Example #26
0
        public LuteBotForm()
        {
            InitializeComponent();

            onlineManager                             = new OnlineSyncManager();
            playList                                  = new PlayListManager();
            trackSelectionManager                     = new TrackSelectionManager();
            playList.PlayListUpdatedEvent            += new EventHandler <PlayListEventArgs>(HandlePlayListChanged);
            soundBoardManager                         = new SoundBoardManager();
            soundBoardManager.SoundBoardTrackRequest += new EventHandler <SoundBoardEventArgs>(HandleSoundBoardTrackRequest);
            player                                       = new MidiPlayer(trackSelectionManager);
            player.SongLoaded                           += new EventHandler <AsyncCompletedEventArgs>(PlayerLoadCompleted);
            hotkeyManager                                = new HotkeyManager();
            hotkeyManager.NextKeyPressed                += new EventHandler(NextButton_Click);
            hotkeyManager.PlayKeyPressed                += new EventHandler(PlayButton_Click);
            hotkeyManager.StopKeyPressed                += new EventHandler(StopButton_Click);
            hotkeyManager.SynchronizePressed            += HotkeyManager_SynchronizePressed;
            hotkeyManager.PreviousKeyPressed            += new EventHandler(PreviousButton_Click);
            trackSelectionManager.OutDeviceResetRequest += new EventHandler(ResetDevice);
            trackSelectionManager.ToggleTrackRequest    += new EventHandler <TrackItem>(ToggleTrack);
            liveMidiManager                              = new LiveMidiManager(trackSelectionManager);
            hotkeyManager.LiveInputManager               = liveMidiManager;

            PlayButton.Enabled       = false;
            StopButton.Enabled       = false;
            PreviousButton.Enabled   = false;
            NextButton.Enabled       = false;
            MusicProgressBar.Enabled = false;


            _hookID = SetHook(_proc);
            OpenDialogs();
            this.StartPosition = FormStartPosition.Manual;
            Point coords = WindowPositionUtils.CheckPosition(ConfigManager.GetCoordsProperty(PropertyItem.MainWindowPos));

            Top  = coords.Y;
            Left = coords.X;

            // We may package this with a guild library for now.  Check for it and extract it, if so
            var files = Directory.GetFiles(Environment.CurrentDirectory, "BGML*.zip", SearchOption.TopDirectoryOnly);

            if (files.Length > 0)
            {
                Task.Run(() =>
                {
                    // extract to libraryPath + "\songs\"
                    try
                    {
                        ZipFile.ExtractToDirectory(files[0], libraryPath + @"\songs\");
                        //File.Delete(files[0]);
                    }
                    catch (Exception e) { } // Gross I know, but no reason to do anything
                });
            }
        }
Example #27
0
        private void port_DataReceived(object sender, SerialDataReceivedEventArgs e)
        {
            // Obtain the number of bytes waiting in the port's buffer
            int bytes = comport.BytesToRead;

            // Create a byte array buffer to hold the incoming data
            byte[] buffer = new byte[bytes];
            comport.Read(buffer, 0, bytes);
            for (int c = 0; c < bytes; c++)
            {
                midiQueue.Enqueue(buffer[c]);
            }
            if (CurrentDataMode == DataMode.Hex)
            {
                Log(LogMsgType.Incoming, ByteArrayToHexString(buffer));
            }
            while (midiQueue.Count > 0)
            {
                midiMsg.Enqueue(midiQueue.Dequeue());
                if (midiMsg.Count == 3)
                {
                    byte byteOne   = midiMsg.Dequeue();
                    byte byteTwo   = midiMsg.Dequeue();
                    byte byteThree = midiMsg.Dequeue();
                    // sanatize everything for MidiPlayer
                    if (byteTwo > 127)
                    {
                        byteTwo = 127;
                    }
                    if (byteThree > 127)
                    {
                        byteThree = 127;
                    }

                    if (byteOne >= 0x90 && byteOne <= 0x9F)
                    {
                        byteOne -= 0x90;
                        MidiPlayer.Play(new NoteOn(1, byteOne, byteTwo, byteThree));
                        if (CurrentDataMode == DataMode.Text)
                        {
                            Log(LogMsgType.Normal, String.Format("Channel: {1} Note: {0} Velocity: {2}", MidiEvent.GetNoteName(byteTwo), byteOne + 1, byteThree));
                        }
                    }
                    else if (byteOne >= 0xB0 && byteOne <= 0xBF)
                    {
                        byteOne -= 0xB0;
                        MidiPlayer.Play(new Controller(0, byteOne, byteTwo, byteThree));
                        if (CurrentDataMode == DataMode.Text)
                        {
                            Log(LogMsgType.Normal, String.Format("Channel: {0} CC: {1} Value: {2}", byteOne + 1, byteTwo, byteThree));
                        }
                    }
                }
            }
        }
    // Update is called once per frame
    public override void OnInspectorGUI()
    {
        serializedObject.Update();

        EditorGUILayout.PropertyField(midi);
        EditorGUILayout.PropertyField(music);
        EditorGUILayout.PropertyField(audioSource);
        EditorGUILayout.PropertyField(playDelayTime);
        EditorGUILayout.PropertyField(playSpeed);

        serializedObject.ApplyModifiedProperties();

        MidiPlayer midiplayer = (MidiPlayer)target;

        if (Application.isPlaying == true)
        {
            GUILayout.BeginHorizontal();
            if (midiplayer.isPlaying == true)
            {
                if (GUILayout.Button("Pause") == true)
                {
                    midiplayer.Pause();
                }

                EditorUtility.SetDirty(target);
            }
            else
            {
                if (midiplayer.playTime == 0)
                {
                    if (GUILayout.Button("Play") == true)
                    {
                        midiplayer.Play();
                    }
                }
                else
                {
                    if (GUILayout.Button("Resume") == true)
                    {
                        midiplayer.Resume();
                    }
                }
            }

            if (GUILayout.Button("Stop") == true)
            {
                midiplayer.Stop();
            }
            GUILayout.EndHorizontal();

            //EditorGUILayout.Slider(midiplayer.playTime, 0f, midiplayer.totalTime);
            GUILayout.HorizontalSlider(midiplayer.playTime, 0f, midiplayer.totalTime);
            EditorGUILayout.LabelField(string.Format("Time : {0:f1}sec", midiplayer.playTime));
        }
    }
Example #29
0
 private void OutputOnBuffer(object?sender, OutputBufferEventArgs e)
 {
     if (Recorder != null)
     {
         e.Buffer = Recorder.Next(e.Size);
     }
     else
     {
         e.Buffer = MidiPlayer.Next(e.Size);
     }
 }
Example #30
0
 private void PlayNote(BaloonModel baloon)
 {
     noteTimer.Stop();
     if (currentNote != null)
     {
         MidiPlayer.Play(new NoteOff(0, 1, currentNote, 127));
     }
     currentNote = baloon.Note;
     MidiPlayer.Play(new NoteOn(0, 1, currentNote, 127));
     noteTimer.Start();
 }
Example #31
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();
        }
 public void ProcessBeginPlay(MidiPlayer player, int totalMilliseconds)
 {
     timer.Start ();
 }
Example #33
0
 internal void ProcessPlay()
 {
     DrawCommon("XXXXX");
     if (smf_music == null)
         return;
     if (media_player == null) {
         try {
             media_player = new MediaPlayer ();
             media_player.SetDataSource(jetfile.FullName);
             media_player.Prepare();
         } catch (IOException ex) {
             media_player = null;
             DrawCommon ("failed to load SMF");
             return;
         }
     }
     if (midi_player == null) {
         midi_player = new MidiPlayer (smf_music);
         midi_player.Finished += delegate { StopViews(); };
         midi_player.MessageReceived += HandleSmfMessage;
     }
     // This state check is not necessary for MidiPlayer,
     // but for JetPlayer (which does not expose state).
     if (midi_player.State != PlayerState.Playing) {
         midi_player.PlayAsync();
         media_player.Start();
     }
     DrawCommon ("PLAY");
 }
Example #34
0
 internal void ProcessStop()
 {
     if (midi_player == null)
         return;
     midi_player.Dispose();
     midi_player = null;
     if (media_player != null) {
         media_player.Stop();
         media_player = null;
     }
     DrawCommon ("STOP");
 }
Example #35
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");
        }