void OnTransitionReady() { executedTransition_ = null; if (requenstedTransition_ != null) { SetNextSection(requenstedTransition_); } else { switch (CurrentSection.TransitionType) { case MusicSection.AutoTransitionType.Loop: SetNextLoop(); break; case MusicSection.AutoTransitionType.Transition: SetNextSection(new SectionTransitionParam(CurrentSection.TransitionDestinationIndex, this, Music.SyncType.ExitPoint)); break; case MusicSection.AutoTransitionType.End: nextSectionIndex_ = -1; endScheduledDSPTime_ = 0.0; break; } } }
protected override void ResetParamsInternal() { currentSample_ = 0; sectionIndex_ = 0; nextSectionIndex_ = -1; prevSectionIndex_ = -1; requenstedTransition_ = null; modeIndex_ = 0; nextModeIndex_ = 0; requestedModeIndex_ = -1; endScheduledDSPTime_ = 0.0; syncScheduledDSPTime_ = 0.0; ModeTransitionState = EModeTransitionState.Invalid; TransitionState = ETransitionState.Invalid; }
public override void SetHorizontalSequenceByIndex(int index) { if (index < 0 || Sections.Length <= index // インデックス範囲外 || index == nextSectionIndex_ // 既に遷移確定済み || (requenstedTransition_ != null && requenstedTransition_.SectionIndex == index)) // 既にリクエスト済み { return; } // 再生中以外は設定だけ switch (State) { case Music.PlayState.Invalid: return; case Music.PlayState.Ready: case Music.PlayState.Finished: sectionIndex_ = index; ResetSectionClips(); return; case Music.PlayState.Suspended: requenstedTransition_ = new SectionTransitionParam(index, sectionIndex_, this); return; case Music.PlayState.Playing: break; } // 今と同じセクションが指定されたら if (index == sectionIndex_) { // 予約中のはキャンセル requenstedTransition_ = null; // 遷移中のはキャンセルできるならキャンセル if (TransitionState == ETransitionState.Synced) { CancelSyncedTransition(); OnTransitionReady(); } else if (TransitionState == ETransitionState.PreEntry) { requenstedTransition_ = new SectionTransitionParam(index, sectionIndex_, this); } return; } switch (TransitionState) { case ETransitionState.Invalid: case ETransitionState.Outro: return; case ETransitionState.Intro: case ETransitionState.PreEntry: case ETransitionState.PostEntry: requenstedTransition_ = new SectionTransitionParam(index, sectionIndex_, this); return; default: //case ETransitionState.Ready: //case ETransitionState.Synced: break; } SetNextSection(new SectionTransitionParam(index, sectionIndex_, this)); }
void SetNextSection(SectionTransitionParam param) { // 遷移タイミング計算 MusicSection requestedSection = Sections[param.SectionIndex]; int entryPointSample = requestedSection.EntryPointSample; int currentSample = currentSample_; int syncPointSample = 0; if (FindSyncPoint(param.SyncType, param.SyncFactor, currentSample, entryPointSample, out syncPointSample) == false) { requenstedTransition_ = param; return; } // 遷移状態によって前のをキャンセルしたり switch (TransitionState) { case ETransitionState.Ready: // 準備OK break; case ETransitionState.Synced: // 前のをキャンセル CancelSyncedTransition(); break; case ETransitionState.Intro: case ETransitionState.PreEntry: case ETransitionState.PostEntry: case ETransitionState.Outro: // 遷移できないはずなんですが…… print("invalid transition state " + TransitionState); return; } // 波形終了予約 endScheduledDSPTime_ = 0.0; if (param.Transition.UseFadeOut == false) { if (param.SyncType == Music.SyncType.ExitPoint) { endScheduledDSPTime_ = AudioSettings.dspTime + (double)(musicSources_[0].clip.samples - currentSample) / sampleRate_;; } else { endScheduledDSPTime_ = AudioSettings.dspTime + (double)(syncPointSample - currentSample) / sampleRate_; } } // 遷移波形予約 syncScheduledDSPTime_ = AudioSettings.dspTime + (double)(syncPointSample - currentSample - entryPointSample) / sampleRate_; for (int i = 0; i < NumTracks; ++i) { if (i < requestedSection.Clips.Length) { transitionMusicSources_[i].clip = requestedSection.Clips[i]; transitionMusicSources_[i].timeSamples = 0; transitionMusicSources_[i].PlayScheduled(syncScheduledDSPTime_); } else { transitionMusicSources_[i].clip = null; } if (i < CurrentSection.Clips.Length && endScheduledDSPTime_ > 0) { musicSources_[i].SetScheduledEndTime(endScheduledDSPTime_); } } // 状態遷移 TransitionState = ETransitionState.Synced; nextSectionIndex_ = param.SectionIndex; requenstedTransition_ = null; executedTransition_ = param; // フェード時間計算 transitionFadeOutVolume_ = 1.0f; transitionFadeInVolume_ = 1.0f; if (param.Transition.UseFadeOut) { transitionFadeOut_.SetFade( (int)(param.Transition.FadeOutOffset * sampleRate_) + NextSection.EntryPointSample, (int)(param.Transition.FadeOutTime * sampleRate_)); } if (param.Transition.UseFadeIn) { transitionFadeInVolume_ = 0.0f; transitionFadeIn_.SetFade( (int)(param.Transition.FadeInOffset * sampleRate_), (int)(param.Transition.FadeInTime * sampleRate_)); } UpdateVolumes(); }