示例#1
0
 public static void Play(string moduleName, float delay = 0, AudioPlayerOld.SyncMode syncMode = AudioPlayerOld.SyncMode.None)
 {
     if (Modules.ContainsKey(moduleName))
     {
         Modules[moduleName].Play(delay, syncMode);
     }
 }
示例#2
0
 public void Play(float delay = 0, AudioPlayerOld.SyncMode syncMode = AudioPlayerOld.SyncMode.None)
 {
     delay = (float)(AudioPlayerOld.GetDelayToSync(syncMode) + AudioPlayerOld.GetAdjustedDelay(delay, syncMode));
     Instance.coroutineHolder.AddCoroutine("PDPlayerPlayAfterDelay", PlayAfterDelay(delay));
 }
示例#3
0
    public static AudioSource Play(string instrumentName, int midiNote, float velocity, GameObject sourceObject = null, float delay = 0, AudioPlayerOld.SyncMode syncMode = AudioPlayerOld.SyncMode.None)
    {
        AudioSource  audioSource;
        Instrument   instrument = Instruments[instrumentName];
        AudioInfoOld audioInfo  = AudioPlayerOld.AudioInfos[instrument.referenceClips[midiNote].name];
        AudioClip    audioClip  = null;
        float        initVolume = audioInfo.volume;

        midiNote = GetAdjustedNote(midiNote, velocity, instrument);

        if (!string.IsNullOrEmpty(instrument.originalClips[midiNote]))
        {
            audioClip = instrument.audioClips[midiNote];
        }
        else
        {
            if (instrument.generateMode == Instrument.GenerateModes.None || instrument.generateMode == Instrument.GenerateModes.PreGenerateAll)
            {
                audioClip = instrument.audioClips[midiNote];
            }
            else
            if (instrument.generateMode == Instrument.GenerateModes.GenerateAtRuntime)
            {
                if (instrument.audioClips[midiNote] != null)
                {
                    audioClip = instrument.audioClips[midiNote];
                }

                if (audioClip == null)
                {
                    audioClip = CreateAudioClip(instrument, midiNote);
                }

                if (!audioInfo.loop && instrument.destroyIdle)
                {
                    Instance.coroutineHolder.RemoveCoroutines(instrumentName + midiNote);
                    Instance.coroutineHolder.AddCoroutine(instrumentName + midiNote, RemoveAfterDelay(audioClip, instrument.idleThreshold, (float)(AudioPlayerOld.GetAdjustedDelay(audioInfo.delay, audioInfo.syncMode) + AudioPlayerOld.GetAdjustedDelay(delay, syncMode))));
                }
            }
        }

        if (instrument.velocityAffectsVolume)
        {
            audioInfo.volume *= instrument.velocityCurve.Evaluate(velocity / 127);
        }

        audioSource = AudioPlayerOld.Play(audioClip, audioInfo, sourceObject, delay, syncMode);
        if (instrument.sendToPD)
        {
            audioSource.gameObject.GetOrAddComponent <AudioGainManager>().Initialize(instrument.name + "~");
        }
        instrument.activeVoices.Add(audioSource);

        audioInfo.volume = initVolume;
        return(audioSource);
    }
示例#4
0
 public static List <AudioSource> PlayRepeating(float repeatRate, string instrumentName, int[] midiNotes, float[] velocities, GameObject sourceObject = null, float delay = 0, AudioPlayerOld.SyncMode syncMode = AudioPlayerOld.SyncMode.None)
 {
     return(AudioPlayerOld.PlayRepeating(repeatRate, new Note(instrumentName, midiNotes, velocities), sourceObject, delay, syncMode));
 }
示例#5
0
    public static List <AudioSource> Play(string instrumentName, int[] midiNotes, float[] velocities, GameObject sourceObject = null, float delay = 0, AudioPlayerOld.SyncMode syncMode = AudioPlayerOld.SyncMode.None)
    {
        List <AudioSource> audioSources = new List <AudioSource>();

        for (int i = 0; i < midiNotes.Length; i++)
        {
            audioSources.Add(Play(instrumentName, midiNotes[i], velocities[i], sourceObject, delay, syncMode));
        }
        return(audioSources);
    }
示例#6
0
    public static List <AudioSource> Play(Note note, GameObject sourceObject = null, float delay = 0, AudioPlayerOld.SyncMode syncMode = AudioPlayerOld.SyncMode.None)
    {
        List <AudioSource> audioSources = new List <AudioSource>();

        audioSources.AddRange(Play(note.instrumentName, note.midiNotes, note.velocities, sourceObject, delay, syncMode));
        return(audioSources);
    }