1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     snd_SequenceTrack.h
4 
5   Copyright (C)2009-2010 Nintendo Co., Ltd./HAL Laboratory, Inc.  All rights reserved.
6 
7   These coded instructions, statements, and computer programs contain
8   proprietary information of Nintendo of America Inc. and/or Nintendo
9   Company Ltd., and are protected by Federal copyright law.  They may
10   not be disclosed to third parties or copied or duplicated in any form,
11   in whole or in part, without the prior written consent of Nintendo.
12 
13   $Revision: 22284 $
14  *---------------------------------------------------------------------------*/
15 
16 #ifndef NW_SND_SEQUENCE_TRACK_H_
17 #define NW_SND_SEQUENCE_TRACK_H_
18 
19 #include <nw/snd/snd_Channel.h>
20 #include <nw/snd/snd_CurveLfo.h>
21 #include <nw/snd/snd_MoveValue.h>
22 #include <nw/snd/snd_Global.h>      // SeqMute
23 
24 namespace nw {
25 namespace snd {
26 namespace internal {
27 namespace driver {
28 
29 /* ========================================================================
30         typename declaration
31    ======================================================================== */
32 
33 class SequenceSoundPlayer;
34 
35 /* ========================================================================
36         class definition
37    ======================================================================== */
38 
39 class SequenceTrack
40 {
41     /* ------------------------------------------------------------------------
42             type definition
43        ------------------------------------------------------------------------ */
44   public:
45     static const int CALL_STACK_DEPTH = 3;
46 
47     struct ParserTrackParam
48     {
49         const u8* baseAddr;
50         const u8* currentAddr;
51 
52         bool cmpFlag;
53         bool noteWaitFlag;
54         bool tieFlag;
55         bool monophonicFlag;
56 
57         struct CallStack
58         {
59             u8 loopFlag;
60             u8 loopCount;
61             const u8* address;
62         };
63         CallStack callStack[ CALL_STACK_DEPTH ];
64         u8 callStackDepth;
65 
66         bool frontBypassFlag;
67 
68         s32 wait;
69 
70         bool muteFlag;
71         bool silenceFlag;
72         bool noteFinishWait;
73         bool portaFlag;
74         bool damperFlag;
75 
76         u8  bankIndex;      // 0-3 のシーケンス内バンクインデックスと見る
77         int prgNo;
78 
79         CurveLfoParam lfoParam;
80         u8 lfoTarget; // enum Channel::LfoTarget;
81         f32 sweepPitch;
82 
83         MoveValue<u8,s16> volume;
84         MoveValue<s8,s16> pan;
85         MoveValue<s8,s16> surroundPan;
86         MoveValue<s8,s16> pitchBend;
87         u8 volume2;
88         u8 velocityRange;
89         u8 bendRange;
90         s8 initPan;
91         s8 transpose;
92         u8 priority;
93         u8 portaKey;
94         u8 portaTime;
95         u8 attack;
96         u8 decay;
97         u8 sustain;
98         u8 release;
99         s16 envHold;
100         u8 mainSend;
101         u8 fxSend[ AUX_BUS_NUM ];
102         u8 biquadType;
103         f32 lpfFreq;
104         f32 biquadValue;
105     };
106 
107     enum ParseResult
108     {
109         PARSE_RESULT_CONTINUE,
110         PARSE_RESULT_FINISH
111     };
112 
113     /* ------------------------------------------------------------------------
114             constant variable
115        ------------------------------------------------------------------------ */
116   public:
117     static const int DEFAULT_PRIORITY   = 64;
118     static const int DEFAULT_BENDRANGE  = 2;
119     static const int DEFAULT_PORTA_KEY  = 60; /* cn4 */
120     static const int INVALID_ENVELOPE   = 0xff;
121     static const int MAX_ENVELOPE_VALUE = 0x7f;
122     static const int PARSER_PARAM_SIZE  = 32;
123     static const int TRACK_VARIABLE_NUM = 16;
124 
125     static const int PAUSE_RELEASE_VALUE    = 127;
126     static const int MUTE_RELEASE_VALUE     = 127;
127 
128     /* ------------------------------------------------------------------------
129             static member
130        ------------------------------------------------------------------------ */
131   public:
132     static void ChannelCallbackFunc(
133         Channel* dropChannel,
134         Channel::ChannelCallbackStatus status,
135         u32 userData
136     );
137 
138     /* ------------------------------------------------------------------------
139             class member
140        ------------------------------------------------------------------------ */
141 
142   public:
143     // 初期化・終了処理
144     SequenceTrack();
145     virtual ~SequenceTrack();
146 
147     void InitParam();
148     void SetSeqData( const void* seqBase, s32 seqOffset );
149     void Open();
150     void Close();
IsOpened()151     bool IsOpened() const { return m_OpenFlag; }
152 
153     // 更新処理
154     int ParseNextTick( bool doNoteOn );
155     void UpdateChannelLength();
156     void UpdateChannelParam();
157 
158     // チャンネル操作
159     Channel* NoteOn(
160         int key,
161         int velocity,
162         s32 length,
163         bool tieFlag
164     );
165     void StopAllChannel();
166     void ReleaseAllChannel( int release );
167     void FreeAllChannel();
168     void PauseAllChannel( bool flag );
169 
170     // 情報取得
171     int GetChannelCount() const;
GetParserTrackParam()172     const ParserTrackParam& GetParserTrackParam() const { return m_ParserTrackParam; }
GetParserTrackParam()173     ParserTrackParam& GetParserTrackParam() { return m_ParserTrackParam; }
174 
175     // パラメータ設定
176     void SetMute( SeqMute mute );
177     void SetSilence( bool silenceFlag, int fadeTimes );
SetVolume(float volume)178     void SetVolume( float volume ) { m_ExtVolume = volume; }
SetPitch(float pitch)179     void SetPitch( float pitch ) { m_ExtPitch = pitch; }
SetPan(float pan)180     void SetPan( float pan ) { m_ExtPan = pan; }
SetPanRange(float panRange)181     void SetPanRange( float panRange ) { m_PanRange = panRange; }
SetSurroundPan(float surroundPan)182     void SetSurroundPan( float surroundPan ) { m_ExtSurroundPan = surroundPan; }
SetLpfFreq(float lpfFreq)183     void SetLpfFreq( float lpfFreq ) { m_ParserTrackParam.lpfFreq = lpfFreq; }
184     void SetBiquadFilter( int type, float value );
SetModDepth(float depth)185     void SetModDepth( float depth ) { m_ParserTrackParam.lfoParam.depth = depth; }
SetModSpeed(float speed)186     void SetModSpeed( float speed ) { m_ParserTrackParam.lfoParam.speed = speed; }
187     void SetBankIndex( int bankIdex );
188 
189     // パラメータ取得
GetVolume()190     float GetVolume() const { return m_ExtVolume; }
GetPitch()191     float GetPitch() const { return m_ExtPitch; }
GetPan()192     float GetPan() const { return m_ExtPan; }
GetPanRange()193     float GetPanRange() const { return m_PanRange; }
GetLpfFreq()194     float GetLpfFreq() const { return m_ParserTrackParam.lpfFreq; }
GetBiquadType()195     int GetBiquadType() const { return m_ParserTrackParam.biquadType; }
GetBiquadValue()196     float GetBiquadValue() const { return m_ParserTrackParam.biquadValue; }
GetSurroundPan()197     float GetSurroundPan() const { return m_ExtSurroundPan; }
198 
199     // シーケンス処理
200     s16 GetTrackVariable( int varNo ) const;
201     void SetTrackVariable( int varNo, s16 var );
202     vs16* GetVariablePtr( int varNo );
203 
SetSequenceSoundPlayer(SequenceSoundPlayer * player)204     void SetSequenceSoundPlayer( SequenceSoundPlayer* player ) { m_pSequenceSoundPlayer = player; }
GetSequenceSoundPlayer()205     const SequenceSoundPlayer* GetSequenceSoundPlayer() const { return m_pSequenceSoundPlayer; }
GetSequenceSoundPlayer()206     SequenceSoundPlayer* GetSequenceSoundPlayer() { return m_pSequenceSoundPlayer; }
207 
208     void SetPlayerTrackNo( int playerTrackNo );
GetPlayerTrackNo()209     u8 GetPlayerTrackNo() const { return m_PlayerTrackNo; }
210 
211     void UpdateChannelRelease( Channel* channel );
212 
213   protected:
214     virtual ParseResult Parse( bool doNoteOn ) = 0;
215 
216   private:
GetLastChannel()217     Channel* GetLastChannel() const { return m_pChannelList; }
218     void AddChannel( Channel* channel );
219 
220     u8 m_PlayerTrackNo;
221     bool m_OpenFlag;
222     f32 m_ExtVolume;
223     f32 m_ExtPitch;
224     f32 m_ExtPan;
225     f32 m_ExtSurroundPan;
226     f32 m_PanRange;
227 
228     ParserTrackParam m_ParserTrackParam;
229     vs16 m_TrackVariable[ TRACK_VARIABLE_NUM ];
230 
231     SequenceSoundPlayer* m_pSequenceSoundPlayer;
232     Channel* m_pChannelList;
233 };
234 
235 } // namespace nw::snd::internal::driver
236 } // namespace nw::snd::internal
237 } // namespace nw::snd
238 } // namespace nw
239 
240 
241 #endif /* NW_SND_SEQUENCE_TRACK_H_ */
242 
243