コード例 #1
0
 public static void PlayNext(MidiMessage p_message, MidiSource p_source)
 {
     p_message.noteSource = p_source;
     messOutBuff.Add(p_message);
     if (p_message.getOwnerTrack() != null)
     {
         p_source.trackPPQAbsolutePos = p_message.getAbsTimeStamp(); //this sets write head for ppq
     }
 }
コード例 #2
0
 public static void PlayNext(MidiMessage p_message, MidiSource p_source)
 {
     if (Midi.debugLevel > 4)
     {
         Debug.Log("Add note to play " + p_message.getByteOne() + " " + p_message.getByteTwo() + " at time: " + p_message.getAbsTimeStamp());
     }
     p_message.noteSource = p_source;
     messOutBuff.Add(p_message);
     if (p_message.getOwnerTrack() != null)
     {
         p_source.setTrackPPQAbsolutePos(p_message.getAbsTimeStamp()); //this sets write head for ppq
     }
 }
コード例 #3
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;
                    }
                }
            }
        }