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