Пример #1
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);
        }
Пример #2
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;
                    }
                }
            }
        }
Пример #3
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;
        }
Пример #4
0
 public static void Play(MidiMessage p_message)
 {
     PortMidi.midiEvent(p_message.getStatusByte(), p_message.getByteOne(), p_message.getByteTwo(), 0);
 }