예제 #1
0
 public static int Shutdown()
 {
     PortMidi.shutdown();
     PortMidi.Pm_Terminate();
     //metronomeStartTimeMs = 0;
     return(1);
 }
예제 #2
0
        public static void Play(MidiMessage p_message)
        {
            if (Midi.debugLevel > 4)
            {
                Debug.Log("Add note to play " + p_message.getByteOne());
            }

            PortMidi.midiEvent(p_message.getStatusByte(), p_message.getByteOne(), p_message.getByteTwo(), 0);
        }
예제 #3
0
 private void OnEnable()
 {
     numDevices    = PortMidi.Pm_CountDevices();
     outputDevices = new string[numDevices];
     for (int i = 0; i < numDevices; i++)
     {
         outputDevices[i] = Marshal.PtrToStringAnsi(PortMidi.printOutputDevice(i));
     }
 }
예제 #4
0
        public static void Update()
        {
            double currentTime = (AudioSettings.dspTime) * 1000.0;

            if (messOutBuff.Count > 0)
            {
                MidiMessage temporaryMessage = messOutBuff[0];
                double      msUntilEvent     = temporaryMessage.noteSource.startTimeOffset + Metronome.ppqToMs(temporaryMessage.getAbsTimeStamp()) - currentTime;

                //this while accounts for multiple notes at once
                while (msUntilEvent < updateLookAhead && messOutBuff.Count > 0)
                {
                    long msOffset = (long)(msUntilEvent);
                    if (msOffset < 0)
                    {
                        msOffset = 0;               //catch any rogue startup notes
                    }
                    MidiMessage p_message = messOutBuff[0];
                    messOutBuff.RemoveAt(0);
                    int statusByte;
                    int amplitude;

                    if (p_message.noteSource.ForceToChannel)
                    {
                        statusByte = p_message.getStatusByte() & 0xF0;
                        statusByte = statusByte += p_message.noteSource.Channel - 1;
                    }

                    else
                    {
                        statusByte = p_message.getStatusByte();
                    }

                    if (p_message.noteSource.Mute)
                    {
                        amplitude = 0;
                    }
                    else
                    {
                        amplitude = (int)(p_message.getByteTwo() * p_message.getGain());
                    }


                    PortMidi.midiEvent(statusByte, p_message.getByteOne() + p_message.noteSource.PitchOffset, amplitude, (int)(msOffset));

                    if (messOutBuff.Count > 0)
                    {
                        temporaryMessage = messOutBuff[0];
                        msUntilEvent     = temporaryMessage.noteSource.startTimeOffset + Metronome.ppqToMs(temporaryMessage.getAbsTimeStamp()) - currentTime;
                    }
                }
            }
        }
예제 #5
0
        public static void PlayScheduled(MidiMessage p_message, double p_time)
        {
            if (p_time < AudioSettings.dspTime)
            {
                Debug.Log("<color=yellow>Warning:</color> time must not be in past!");
                return;
            }
            double theTime = AudioSettings.dspTime;

            PortMidi.midiEvent(p_message.getStatusByte(), p_message.getByteOne(), p_message.getByteTwo(),
                               (int)((p_time - theTime) * 1000.0));
            previousEventMS = (p_time - theTime) * 1000.0;
        }
예제 #6
0
 public static int Start()
 {
     if (!hasStarted)
     {
         hasStarted  = true;
         messOutBuff = new List <MidiMessage>();
         return(PortMidi.main_test_output(deviceNum));
     }
     else
     {
         return(-1);
     }
 }
예제 #7
0
 public static void Play(MidiMessage p_message)
 {
     PortMidi.midiEvent(p_message.getStatusByte(), p_message.getByteOne(), p_message.getByteTwo(), 0);
 }