1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     snd_AnimSoundImpl.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: $
16  *---------------------------------------------------------------------------*/
17 
18 #ifndef NW_SND_ANIM_SOUND_IMPL_H_
19 #define NW_SND_ANIM_SOUND_IMPL_H_
20 
21 #include <nn/types.h>
22 #include <nw/snd/snd_AnimSoundFile.h>
23 #include <nw/snd/snd_AnimSoundFileReader.h>
24 
25 namespace nw {
26 namespace snd {
27 
28 class SoundArchive;
29 class SoundStartable;
30 
31 namespace internal {
32 
33 class AnimEventPlayer;
34 
35 class AnimSoundImpl
36 {
37 public:
38     //
39     // 定義
40     //
41     enum EventType
42     {
43         EVENT_TYPE_TRIGGER_START,
44         EVENT_TYPE_TRIGGER_STOP,
45         EVENT_TYPE_RANGE_START,
46         EVENT_TYPE_RANGE_STOP
47     };
48 
49     enum PlayDirection
50     {
51         PLAY_DIRECTION_FORWARD,
52         PLAY_DIRECTION_BACKWARD
53     };
54 
55     typedef void (*EventCallback)(
56         EventType type,
57         s32 frame,
58         const char* soundLabel,
59         u32 userParam,
60         void* arg );
61 
62     //
63     // 関数
64     //
65     AnimSoundImpl(
66             SoundStartable& starter,
67             AnimEventPlayer* eventPlayers,
68             int eventPlayerCount );
69     ~AnimSoundImpl();
70 
71     bool Initialize( const void* bcasdFile );
72     void Finalize();
73     bool ConvertSoundId( const SoundArchive& arc );
IsAvailable()74     bool IsAvailable() const { return m_Reader.IsAvailable(); }
SetBaseStep(f32 baseStep)75     void SetBaseStep( f32 baseStep ) { m_BaseStep = baseStep; }
76 
SetEventCalback(EventCallback callback,void * arg)77     void SetEventCalback( EventCallback callback, void* arg )
78     {
79         m_EventCallback = callback;
80         m_EventCallbackArg = arg;
81     }
82 
83     void ResetFrame( f32 frame, int loopCounter );
84     void UpdateFrame( f32 frame, PlayDirection direction = PLAY_DIRECTION_FORWARD );
85 
86     void StopAllSound();
87 
GetFrameSize()88     u32 GetFrameSize() const { return m_FrameSize; }
GetLoopCount()89     int GetLoopCount() const { return IsAvailable() ? m_LoopCounter : 0; }
GetCurrentFrame()90     f32 GetCurrentFrame() const { return IsAvailable() ? m_CurrentFrame : 0.0f; }
91 
92 private:
93     void UpdateForward( f32 frame );
94     void UpdateBackward( f32 frame );
95     void UpdateOneFrame( s32 current, PlayDirection direction );
96 
97     void UpdateTrigger(
98             const AnimSoundFile::AnimEvent& event,
99             s32 current,
100             PlayDirection direction );
101     void UpdateRange(
102             const AnimSoundFile::AnimEvent& event,
103             s32 current,
104             PlayDirection direction );
105 
106     void UpdateForwardRange( const AnimSoundFile::AnimEvent& event, s32 current );
107     void UpdateBackwardRange( const AnimSoundFile::AnimEvent& event, s32 current );
108 
109     void StartEvent( const AnimSoundFile::EventInfo& info, bool isStopWhenFinalize );
110     void HoldEvent( const AnimSoundFile::EventInfo& info, bool isStopWhenFinalize );
111     void StopEvent( const AnimSoundFile::EventInfo& info );
112 
113     bool IsPlayableLoopCount( const AnimSoundFile::FrameInfo& info );
114     void WritePlaySpeedToSequenceVariable(
115             int eventPlayerNo, const AnimSoundFile::EventInfo& info );
116 
117     SoundStartable& m_Starter;
118     AnimSoundFileReader m_Reader;
119     AnimEventPlayer* m_pEventPlayers;
120 
121     EventCallback m_EventCallback;
122     void* m_EventCallbackArg;
123 
124     f32 m_CurrentFrame;
125     int m_EventPlayerCount;
126     bool m_IsActive;
127     bool m_IsInitFrame;
128     bool m_IsReset;
129     s32 m_LoopCounter;
130     f32 m_BaseStep;
131     f32 m_CurrentSpeed;
132     s32 m_FrameSize;    // 何度も参照するのでキャッシュしておく
133 };
134 
135 } // namespace nw::snd::internal
136 } // namespace nw::snd
137 } // namespace nw
138 
139 
140 #endif /* NW_SND_ANIM_SOUND_IMPL_H_ */
141 
142