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