示例#1
0
    public void Validate(int sampleRate)
    {
        IsValid = false;
        if (Clips.Length == 0 || Clips[0] == null || Meters.Length == 0)
        {
            return;
        }

        // 最初のメーターをValidateして、EntryPointのサンプル数を計算
        Meters[0].OnValidate(sampleRate, 0);
        EntryPointSample = Meters[0].GetSampleFromTiming(EntryPointTiming);

        // 後続のメーターすべてをValidate
        int startSample = EntryPointSample;
        MusicMeterBySample lastMeter = null;

        foreach (MusicMeterBySample meter in Meters)
        {
            if (lastMeter != null)
            {
                startSample += lastMeter.SamplesPerBar * meter.StartBar;
            }
            meter.OnValidate(sampleRate, startSample);
            lastMeter = meter;
        }

        ClipEndTiming = lastMeter.GetTimingFromSample(Clips[0].samples);
        // 波形終わりのタイミングを参考にExitPointを設定する
        if (ExitPointTiming <= EntryPointTiming || ClipEndTiming < ExitPointTiming)
        {
            ExitPointTiming = new Timing(ClipEndTiming);
            ExitPointTiming.FixToFloor();
        }
        if (ClipEndTiming < LoopEndTiming)
        {
            LoopEndTiming = new Timing(ClipEndTiming);
            LoopEndTiming.FixToFloor();
        }

        if (TransitionType == AutoTransitionType.Loop)
        {
            // LoopEndはLoopStartより後じゃないとダメ
            if (LoopStartTiming >= LoopEndTiming)
            {
                LoopEndTiming.Set(ExitPointTiming);
            }
            // ExitPointはLoopEndと同一
            ExitPointTiming = LoopEndTiming;

            LoopStartSample = GetSampleFromTiming(LoopStartTiming);
            LoopEndSample   = GetSampleFromTiming(LoopEndTiming);
        }

        ExitPointSample = GetSampleFromTiming(ExitPointTiming);

        IsValid = true;
    }