1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: snd_ExternalSoundPlayer.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_EXTERNAL_SOUND_PLAYER_H_
19 #define NW_SND_EXTERNAL_SOUND_PLAYER_H_
20
21 #include <nw/ut/ut_LinkList.h>
22 #include <nw/snd/snd_BasicSound.h>
23
24 namespace nw {
25 namespace snd {
26
27 class SoundActor;
28
29 namespace internal {
30
31 /* ========================================================================
32 class difinition
33 ======================================================================== */
34
35 class ExternalSoundPlayer
36 {
37 /* ------------------------------------------------------------------------
38 typename definition
39 ------------------------------------------------------------------------ */
40 public:
41 typedef ut::LinkList< BasicSound, offsetof(BasicSound,m_ExtSoundPlayerPlayLink)> SoundList;
42
43 /* ------------------------------------------------------------------------
44 class member
45 ------------------------------------------------------------------------ */
46 public:
47 ExternalSoundPlayer();
48 ~ExternalSoundPlayer();
49
50 void StopAllSound( int fadeFrames );
51 void PauseAllSound( bool flag, int fadeFrames );
52
53 // 同時再生数
GetPlayingSoundCount()54 int GetPlayingSoundCount() const { return static_cast<int>( m_SoundList.GetSize()); }
55 void SetPlayableSoundCount( int count );
GetPlayableSoundCount()56 int GetPlayableSoundCount() const { return m_PlayableCount; }
57
58 // プレイヤーでサウンドを再生可能かどうかを調べる
59 bool detail_CanPlaySound( int startPriority );
60
61 // サウンド登録
62 bool AppendSound( internal::BasicSound* sound );
63 void RemoveSound( internal::BasicSound* sound );
64
65 // 全てのサウンドに対する処理
66 template< class Function >
67 Function ForEachSound( Function function, bool reverse = false );
68
69 void Finalize( SoundActor* actor );
70
71 private:
72 internal::BasicSound* GetLowestPrioritySound();
73
74 SoundList m_SoundList;
75 int m_PlayableCount;
76 };
77
78 template< class Function >
ForEachSound(Function function,bool reverse)79 inline Function ExternalSoundPlayer::ForEachSound( Function function, bool reverse )
80 {
81 if ( reverse )
82 {
83 // 再生の新しい順
84 for ( SoundList::ReverseIterator itr = m_SoundList.GetBeginReverseIter();
85 itr != m_SoundList.GetEndReverseIter();
86 )
87 {
88 SoundList::ReverseIterator curItr = itr;
89 SoundHandle handle;
90 handle.detail_AttachSoundAsTempHandle( &( *curItr ) );
91 function( handle );
92 if ( handle.IsAttachedSound() ) itr++;
93 }
94 }
95 else
96 {
97 // 再生の古い順
98 for ( SoundList::Iterator itr = m_SoundList.GetBeginIter();
99 itr != m_SoundList.GetEndIter();
100 )
101 {
102 SoundList::Iterator curItr = itr++;
103 SoundHandle handle;
104 handle.detail_AttachSoundAsTempHandle( &( *curItr ) );
105 function( handle );
106 }
107 }
108 return function;
109 }
110
111 } // namespace nw::snd::internal
112 } // namespace nw::snd
113 } // namespace nw
114
115
116 #endif /* NW_SND_EXTERNAL_SOUND_PLAYER_H_ */
117
118