Пример #1
0
 void Awake()
 {
     if (!Application.isPlaying)
     {
         return;
     }
     MidiPlayer.deviceNum = midiOutputDevice;
     MidiPlayer.Start();
     Metronome.setBPM(bpm);
     previousBpm = bpm;
 }
Пример #2
0
        void Update()
        {
            if (!Application.isPlaying)
            {
                return;
            }
            MidiPlayer.Update();

            if (bpm != previousBpm)
            {
                Metronome.setBPM(bpm);
                previousBpm = bpm;
            }
        }
Пример #3
0
 public static void StartMetronome(int p_BPM)
 {
     Metronome.setBPM(p_BPM);
     metronomeStartTimeMs = AudioSettings.dspTime * 1000;
 }
Пример #4
0
 public static void SetBPM(int p_BPM)
 {
     Metronome.setBPM(p_BPM);
 }
Пример #5
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;
                    }
                }
            }
        }