File: VibratoPointIteratorByClock.cs

package info (click to toggle)
cadencii 3.3.9%2Bsvn20110818.r1732-6
  • links: PTS
  • area: main
  • in suites: buster
  • size: 35,916 kB
  • sloc: cs: 160,836; java: 42,449; cpp: 7,605; ansic: 1,728; perl: 1,087; makefile: 236; php: 142; xml: 117; sh: 21
file content (133 lines) | stat: -rw-r--r-- 4,695 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/*
 * VibratoPointItertorByClock.cs
 * Copyright © 2010-2011 kbinani
 *
 * This file is part of org.kbinani.cadencii.
 *
 * org.kbinani.cadencii is free software; you can redistribute it and/or
 * modify it under the terms of the GPLv3 License.
 *
 * org.kbinani.cadencii is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 */
#if JAVA
package org.kbinani.cadencii;

import java.util.*;
import org.kbinani.vsq.*;
#else
using System;
using org.kbinani.vsq;
using org.kbinani.java.util;

namespace org.kbinani.cadencii {
    using boolean = System.Boolean;
#endif

    /// <summary>
    /// ビブラート用のデータ点のリストを取得します。返却されるリストは、{クロック, ビブラートの振幅(ノートナンバー単位)}の値ペアとなっています
    /// </summary>
#if JAVA
    public class VibratoPointIteratorByClock implements Iterator<Double> {
#else
    public class VibratoPointIteratorByClock : Iterator<Double> {
#endif
        VsqFileEx mVsq;
        VibratoBPList mRate;
        int mStartRate;
        VibratoBPList mDepth;
        int mStartDepth;
        int mClockStart;
        int mClockWidth;

        double mSec0;
        double mSec1;
        double mPhase = 0.0;
        double mAmplitude;
        float mPeriod;
        float mOmega;
        double mSec;
        float mFadeWidth;
        int mIndex;
        boolean mFirst = true;

        public void rewind() {
            mSec0 = mVsq.getSecFromClock( mClockStart );
            mSec1 = mVsq.getSecFromClock( mClockStart + mClockWidth );
            mFadeWidth = (float)(mSec1 - mSec0) * 0.2f;
            mPhase = 0;
            mStartRate = mRate.getValue( 0.0f, mStartRate );
            mStartDepth = mDepth.getValue( 0.0f, mStartDepth );
            mAmplitude = mStartDepth * 2.5f / 127.0f / 2.0f; // ビブラートの振幅。
            mPeriod = VibratoPointIteratorBySec.getPeriodFromRate( mStartRate ); //ビブラートの周期、秒
            mOmega = (float)(2.0 * Math.PI / mPeriod); // 角速度(rad/sec)
            mSec = mSec0;
            mIndex = 0;
            mFirst = true;
        }

        public Double next() {
            if ( mFirst ) {
                mFirst = false;
                return 0.0;
            } else {
                mIndex++;
                if ( mIndex < mClockWidth ) {
                    int clock = mClockStart + mIndex;
                    double t_sec = mVsq.getSecFromClock( clock );
                    if ( mSec0 <= t_sec && t_sec <= mSec0 + mFadeWidth ) {
                        mAmplitude *= (t_sec - mSec0) / mFadeWidth;
                    }
                    if ( mSec1 - mFadeWidth <= t_sec && t_sec <= mSec1 ) {
                        mAmplitude *= (mSec1 - t_sec) / mFadeWidth;
                    }
                    mPhase += mOmega * (t_sec - mSec);
                    double ret = mAmplitude * Math.Sin( mPhase );
                    float v = (float)(clock - mClockStart) / (float)mClockWidth;
                    int r = mRate.getValue( v, mStartRate );
                    int d = mDepth.getValue( v, mStartDepth );
                    mAmplitude = d * 2.5f / 127.0f / 2.0f;
                    mPeriod = VibratoPointIteratorBySec.getPeriodFromRate( r );
                    mOmega = (float)(2.0 * Math.PI / mPeriod);
                    mSec = t_sec;
                    return ret;
                } else {
                    return 0.0;
                }
            }
        }

        public boolean hasNext() {
            if ( mFirst ) {
                return true;
            } else {
                return (mIndex < mClockWidth);
            }
        }

        public void remove() {
        }

        public VibratoPointIteratorByClock( VsqFileEx vsq,
                                      VibratoBPList rate,
                                      int start_rate,
                                      VibratoBPList depth,
                                      int start_depth,
                                      int clock_start,
                                      int clock_width ) {
            this.mVsq = vsq;
            this.mRate = rate;
            this.mStartRate = start_rate;
            this.mDepth = depth;
            this.mStartDepth = start_depth;
            this.mClockStart = clock_start;
            this.mClockWidth = clock_width;

            rewind();
        }
    }

#if !JAVA
}
#endif