/// Plays a single clips private IEnumerator PlaySingleClip(Toggle isRepeatingToggle) { if (mSingleClip == null) { mSingleClip = gameObject.AddComponent <SingleClip>(); string clipName = "AAADefault.txt"; /// This already exists in the IntrumentClips folder. we load it below with Init(). ClipSave clipSave = null; yield return(StartCoroutine(mMusicGenerator.mMusicFileConfig.LoadClipConfigurations(clipName, (x) => { clipSave = x; }))); mSingleClip.Init(clipSave); mSingleClip.mIsRepeating = isRepeatingToggle.isOn; } // mSingleClip.ResetClip();///Just in case it was already playing mSingleClip.SetState(eClipState.Play); }
///stages a clip for playing. Async version (will load assets on the fly). public IEnumerator AsyncStageClipForPlaying() { ClearCurrentInstruments(); bool isFinished = false; StartCoroutine(AsyncLoadClip(((x) => { isFinished = x; }), mPlayClipDropdown.options[mPlayClipDropdown.value].text)); yield return(new WaitUntil(() => isFinished)); mCurrentInstSet = mLoadedClip.mInstrumentSet; InstrumentListPanelUI listPanel = InstrumentListPanelUI.Instance; for (int i = 0; i < mCurrentInstSet.mInstruments.Count; i++) { listPanel.AddInstrument(mCurrentInstSet.mInstruments[i]); InstrumentListUIObject icon = listPanel.mInstrumentIcons[listPanel.mInstrumentIcons.Count - 1]; icon.mInstrument = mCurrentInstSet.mInstruments[i]; icon.ToggleSelected(); bool isPercussion = icon.mInstrument.mData.InstrumentType.Contains("p_") ? true : false; icon.SetDropdown(isPercussion); InstrumentPanelUI.Instance.SetInstrument(icon.mInstrument); mInstrumentPanel.mInstrument = mCurrentInstSet.mInstruments[i]; } InstrumentPanelUI.Instance.SetInstrument(mCurrentInstSet.mInstruments[0]); mInstrumentPanel.mInstrument = mCurrentInstSet.mInstruments[0]; mClipIsRepeating.isOn = mLoadedClip.mIsRepeating; mCurrentMeasure.value = 0; mLoadedClip.SetState(eClipState.Stop); mMusicGenerator.ClipLoaded.Invoke(mCurrenClipSave); mMusicGenerator.ResetPlayer(); mMusicGenerator.SetState(eGeneratorState.editing); ToggleHelperNotes(); UIToggleAllInstruments(); yield return(null); }