Play() public méthode

public Play ( TextAsset midiFile = null ) : void
midiFile UnityEngine.TextAsset
Résultat void
Exemple #1
0
    void FixedUpdate()
    {
        //dsptime = AudioSettings.dspTime;

        if (playTuggle == true && TargetFound == false)
        {
            LoadMidiPath();
        }

        if (playTuggle == true && TargetFound == true)
        {
            if (firstPlay)
            {
                //LoadMidiPath ();
                midi_p.LoadMidi(new MidiFile(midiSource));
                dsptime = AudioSettings.dspTime;
                midi_p.Play();
                firstPlay = false;
            }

            if (midi_p.Sequencer.IsPlaying == true && midi_p.Sequencer.EndTime - midi_p.Sequencer.CurrentTime < 1500)
            {
                LoadMidiPath();
                midi_pb.LoadMidi(new MidiFile(midiSource));
            }
            if (midi_pb.Sequencer.IsPlaying == true && midi_pb.Sequencer.EndTime - midi_pb.Sequencer.CurrentTime < 1500)
            {
                LoadMidiPath();
                midi_p.LoadMidi(new MidiFile(midiSource));
            }

            wakarantime += Time.fixedDeltaTime;
            //if (wakarantime > 0.49 * 4) {
            //if (wakarantime > (midi_p.bpm * 0.00412 * 4)) {
            //if (wakarantime >= ((1 / (((float)midi_p.bpm / 60)) - 0.015) * 4)) {
            if ((AudioSettings.dspTime - dsptime) >= ((1 / (((float)midi_p.bpm / 60)) - 0.015) * 4))
            {
                //Debug.Log ("calc : " + ((1 / ((float)midi_p.bpm / 60)) - 0.005));
                if (count == 0)
                {
                    midi_pb.Play();
                    count++;
                    //LoadMidiPath ();
                    //midi_p.LoadMidi (new MidiFile (midiSource));
                }
                else
                {
                    midi_p.Play();
                    count--;
                    //LoadMidiPath ();
                    //midi_pb.LoadMidi (new MidiFile (midiSource));
                }
                wakarantime = 0;
                dsptime     = AudioSettings.dspTime;
            }
        }
    }
Exemple #2
0
 public PianoRollModel()
 {
     _notesByKeys = GetNotesByKeysFromDB();
     MidiPlayer.OpenMidi();//Iniciem el objecte MIDI
     volume = 63;
     MidiPlayer.Play(new ProgramChange(0, 0, generalInstrument));
 }
Exemple #3
0
 public void PlayMIDI()
 {
     if (player != null)
     {
         player.Play(midiManager.domain);
     }
 }
Exemple #4
0
    void PlayMidi(string name)
    {
        if (midiPlayer != null)
        {
            MidiFile midi    = null;
            DataType musType = wad.DetectType(name);
            if (musType == DataType.MIDI)
            {
                midi = new MidiFile(wad.GetLump(name));
            }
            else if (musType == DataType.MUS)
            {
                midi = new MidiFile(new Mus2Mid(wad.GetLump(name)).MidiData());
            }
            else
            {
                Debug.LogError("Not a midi or mus which are the only thigns supported rn surprisingly enough");
            }

            if (midi != null)
            {
                midiPlayer.Stop();
                midiPlayer.LoadMidi(midi);
                midiPlayer.Play();
            }
        }
    }
Exemple #5
0
        void PlotData(float x, float y, float z)
        {
            this.chart1.BeginInvoke((MethodInvoker) delegate {
                chart1.Series["accX"].Points.AddY(x);
                chart1.Series["accY"].Points.AddY(y);
                chart1.Series["accZ"].Points.AddY(z);

                if (chart1.Series["accX"].Points.Count > 200)
                {
                    chart1.Series["accX"].Points.RemoveAt(0);
                    chart1.Series["accY"].Points.RemoveAt(0);
                    chart1.Series["accZ"].Points.RemoveAt(0);
                }
                curX = x;
                curY = y;
                curZ = z;

                if (z > 15 && !playLock)
                {
                    GeneralMidiPercussion percussion = (GeneralMidiPercussion)Enum.Parse(typeof(GeneralMidiPercussion), comboBox2.SelectedItem.ToString(), true);
                    MidiPlayer.Play(new NoteOn(0, percussion, 127));
                    playLock = true;
                }

                if (z < 15 && playLock)
                {
                    playLock = false;
                }
            });
        }
Exemple #6
0
        private void timer1_Tick(object sender, EventArgs e)
        {
            if (currentNoteDuration == 0)
            {
                if (playPosition >= 1)
                {
                    Note previousNote = myNotes[playPosition - 1];
                    MidiPlayer.Play(new NoteOff(0, 1, previousNote.ToString(), 100));
                }

                Note currentNote = myNotes[playPosition];
                MidiPlayer.Play(new NoteOn(0, 1, currentNote.ToString(), 100));

                Console.WriteLine(currentNote.ToString());

                currentNoteDuration = (int)currentNote.Duration;
                if (currentNote.Dotted)
                {
                    currentNoteDuration *= (int)1.5;
                }
                currentNoteDuration--;

                playPosition++;
                if (playPosition >= myNotes.Count)
                {
                    timer1.Enabled  = false;
                    button1.Enabled = true;
                }
            }
            else
            {
                currentNoteDuration--;
            }
        }
Exemple #7
0
        static void Main(string [] args)
        {
            MidiSequence sampleSequence = new CreateAndPlayDemo().CreateSequence();

            sampleSequence = MidiSequence.Import("C:/Download/test.mid");
            MidiPlayer.Play(sampleSequence);
        }
Exemple #8
0
    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();

            // 재생시간 Bar를 그려주는 역할이다.
            GUILayout.HorizontalSlider(midiPlayer.playTime, 0f, midiPlayer.totalTime);
            EditorGUILayout.LabelField(string.Format("Time : {0:F1} sec", midiPlayer.playTime));
        }
    }
Exemple #9
0
        private void PlayPlayer()
        {
            // spin wait until stopped, if pending a stop
            while (isStopping)
            {
                Thread.Sleep(100);
            }

            if (currentplayer == null)
            {
                var music = getMusic();
                if (music != null)
                {
                    outputDevice                          = getDevice();
                    currentplayer                         = new MidiPlayer(music, outputDevice);
                    jukebox.Current.TotalTime             = currentplayer.GetTotalPlayTimeMilliseconds();
                    jukebox.Current.CurrentTime           = TimeSpan.FromMilliseconds(0);
                    jukebox.Current.RemainingTime         = TimeSpan.FromMilliseconds(jukebox.Current.TotalTime);
                    currentplayer.PlaybackCompletedToEnd += player_Finished;
                    currentplayer.EventReceived          += player_EventReceived;
                    currentplayer.Play();
                    jukebox.Current.State = States.Playing;
                }
                else
                {
                    // found a missing/bad file; so signal move ahead
                    signal_next();
                }
            }
        }
Exemple #10
0
        static void Main(string[] args)
        {
            Stopwatch stopwatch = new Stopwatch();

            Console.Write("Enter seed: ");
            string seed = Console.ReadLine();

            Console.WriteLine("Generating Midi...");

            stopwatch.Restart();

            // Generate a MIDI using Abundant Music
            using (Composition composition = MidiComposer.Compose(seed))
            {
                stopwatch.Stop();
                Console.WriteLine("Seed: " + composition.Seed);
                Console.WriteLine("Generated in: " + stopwatch.Elapsed);

                // Play the MIDI using managed-midi
                // https://github.com/atsushieno/managed-midi
                var access = MidiAccessManager.Default;
                var music  = MidiMusic.Read(composition.Midi);
                using (var player = new MidiPlayer(music, access))
                {
                    long totalPlayTime = player.GetTotalPlayTimeMilliseconds();
                    Console.WriteLine("Play time: " + TimeSpan.FromMilliseconds(totalPlayTime).ToString("g"));

                    player.Play();

                    while (player.State == PlayerState.Playing)
                    {
                    }
                }
            }
        }
        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); }
        }
        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); }
        }
 private void PlayButtonClick(object sender, RoutedEventArgs e)
 {
     foreach (Note note in Music)
     {
         MidiPlayer.Play(note.Tone);
         System.Threading.Thread.Sleep(note.Tempo);
     }
 }
Exemple #14
0
    void ShowKeyboard()
    {
        Rect position      = EditorGUILayout.BeginHorizontal();
        Rect whitePosition = position.Clone();

        whitePosition.width  = 10;
        whitePosition.height = 36;
        whitePosition.y     += 4;
        GUILayout.Box("", GUILayout.Height(40));
        for (int i = 0; i < 21; i++)
        {
            if (GUI.Button(whitePosition, ""))
            {
                midiPlayer.Play(whiteKeysMidiNotes[i] + midiPlayer.octave * 12);
            }
            if (i % 7 != 2 && i % 7 != 6)
            {
                whitePosition.x += whitePosition.width + 4;
            }
            else
            {
                whitePosition.x += whitePosition.width - 3;
            }
        }
        Rect blackPosition = position.Clone();

        blackPosition.width  = 10;
        blackPosition.height = 25;
        blackPosition.x     += (whitePosition.width + 4) / 2;
        for (int i = 0; i < 20; i++)
        {
            if (i % 7 != 2 && i % 7 != 6)
            {
                if (GUI.Button(blackPosition, ""))
                {
                    midiPlayer.Play(blackKeysMidiNotes[i] + midiPlayer.octave * 12);
                }
                blackPosition.x += whitePosition.width + 4;
            }
            else
            {
                blackPosition.x += whitePosition.width - 3;
            }
        }
        EditorGUILayout.EndHorizontal();
    }
Exemple #15
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));
     }
 }
Exemple #16
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));
 }
Exemple #17
0
 private void soltarNota(string tecla)
 {
     if (tecles.Contains(tecla))
     {
         tecles.Remove(tecla);
         MidiPlayer.Play(new NoteOff(0, canal, tecla_notes[tecla], volum));
     }
 }
Exemple #18
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));
     }
 }
Exemple #19
0
 public static void sound(string note)
 {
     OpenMidi();
     MidiPlayer.Play(new NoteOn(0, 1, note, 100));
     if (!notesPlayed.Contains(note))
     {
         notesPlayed.Add(note);
     }
 }
Exemple #20
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();
        }
Exemple #21
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();
        }
Exemple #22
0
 void PlayMidi(string name)
 {
     if (midiPlayer != null)
     {
         midiPlayer.Stop();
         MidiFile midi = new MidiFile(wad.GetLump(name));
         midiPlayer.LoadMidi(midi);
         midiPlayer.Play();
     }
 }
Exemple #23
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));
            }
        }
    // 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));
        }
    }
Exemple #25
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));
                        }
                    }
                }
            }
        }
Exemple #26
0
    static void Main()
    {
        string strPrelude = CheckIfFileExists("BachCSharpPrelude.txt");
        string strFugue   = CheckIfFileExists("BachCSharpFugue.txt");

        if (strPrelude == null || strFugue == null)
        {
            Console.WriteLine("Cannot find music files.");
            return;
        }

        int iInstrument = GetInteger("Enter instrument 0 through 127\r\n" +
                                     "\t(0 = Grand Piano, 6 = Harpsichord, 20 = Reed Organ)\r\n" +
                                     "\t\tor press Enter for piano: ", 0, 127, 0);

        int iVolume = GetInteger("Enter volume 1 through 127" +
                                 " or press Enter for default of 127: ", 1, 127, 127);

        int iPreludeTempo = GetInteger("Enter tempo for prelude" +
                                       " (70 through 280 quarter notes per minute)\r\n" +
                                       "\tor press Enter for default of 140: ", 70, 280, 140);

        int iFugueTempo = GetInteger("Enter tempo for fugue" +
                                     " (55 through 220 quarter notes per minute)\r\n" +
                                     "\tor press Enter for default of 110: ", 55, 220, 110);

        using (Midi midi = new Midi())
        {
            MidiPlayer mp = new MidiPlayer(midi, strPrelude,
                                           iInstrument, iVolume);

            ManualResetEvent[] amre = mp.Play(iPreludeTempo);
            Console.Write("Playing the Prelude... ");
            ManualResetEvent.WaitAll(amre);
            mp.Stop();
            Console.WriteLine("");
            foreach (ManualResetEvent mre in amre)
            {
                mre.Close();
            }

            mp = new MidiPlayer(midi, strFugue, iInstrument, iVolume);

            amre = mp.Play(iFugueTempo);
            Console.Write("Playing the Fugue... ");
            ManualResetEvent.WaitAll(amre);
            mp.Stop();
            Console.WriteLine("");
            foreach (ManualResetEvent mre in amre)
            {
                mre.Close();
            }
        }
    }
Exemple #27
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();
 }
Exemple #28
0
 private void PlayButton_Click(object sender, EventArgs e)
 {
     if (PlayButton.Enabled)
     {
         if (isDonePlaying)
         {
             player.Stop();
             player.Play();
             playButtonIsPlaying = false;
             isDonePlaying       = false;
         }
         if (!playButtonIsPlaying)
         {
             Play();
         }
         else
         {
             Pause();
         }
     }
 }
Exemple #29
0
 public void ResumePlayer()
 {
     if (currentplayer == null)
     {
         return;
     }
     if (currentplayer.State != PlayerState.Playing)
     {
         currentplayer.Play();
         jukebox.Current.State = States.Playing;
     }
 }
Exemple #30
0
        private void btnFindNote_Click(object sender, EventArgs e)
        {
            int    pitch, code;
            string note;
            Color  noteColor = new Color();

            MidiPlayer.Play(new ProgramChange(0, 1, GeneralMidiInstruments.AcousticGrand));

            if ((cmbNote.Text == "") || (cmbPitch.Text == ""))
            {
                MessageBox.Show("Please select note and pitch", "Error");
            }
            else if (cmbPitch.Text == "All")
            {
                int   i;
                int[] codes = { 0, 0, 0, 0, 0 };
                note = cmbNote.Text;
                for (i = 2; i <= 6; i++)
                {
                    codes[i - 2] = Note.ConvertNotationToCode(note, i);
                    MidiPlayer.Play(new NoteOn(0, 1, (note + i.ToString()), 127));
                    this.notes.Add(codes[i - 2], 1, 500);
                    noteColor = this.notes.GetColor(codes[i - 2]);
                    guitar.DyeFretsWithCode(codes[i - 2], noteColor);
                    piano.DyeKeysWithCode(codes[i - 2], noteColor);
                }
            }
            else
            {
                note  = cmbNote.Text;
                pitch = Convert.ToInt32(cmbPitch.Text);
                code  = Note.ConvertNotationToCode(note, pitch);

                MidiPlayer.Play(new NoteOn(0, 1, (note + cmbPitch.Text), 127));

                if (notes.HasCode(code))
                {
                    string color;
                    color = notes.GetColor(code).Name;
                    MessageBox.Show("This Note is already selected!\nIt is colored " + color);
                }
                else
                {
                    this.notes.Add(code, 1, 500);
                    noteColor = this.notes.GetColor(code);

                    guitar.DyeFretsWithCode(code, noteColor);
                    piano.DyeKeysWithCode(code, noteColor);
                }
            }
            lblTitle.Focus();
        }