1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     snd_WaveSoundHandle.cpp
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 #include "precompiled.h"
19 
20 #include <nw/snd/snd_WaveSoundHandle.h>
21 #include <nw/snd/snd_SoundHandle.h>
22 
23 namespace nw {
24 namespace snd {
25 
WaveSoundHandle(SoundHandle * handle)26 WaveSoundHandle::WaveSoundHandle( SoundHandle* handle )
27 : m_pSound( NULL )
28 {
29     if ( handle == NULL ) return;
30 
31     // 汎用ハンドルからサウンドを取得
32     if ( !handle->IsAttachedSound() ) return;
33 
34     internal::WaveSound* sound =
35         ut::DynamicCast<internal::WaveSound*>( handle->detail_GetAttachedSound() );
36 
37     if ( sound != NULL )
38     {
39         // シーケンスサウンドなら一時ハンドルとしてAttachする
40         detail_AttachSoundAsTempHandle( sound );
41     }
42 }
43 
44 /*---------------------------------------------------------------------------*
45   Name:         detail_AttachSoundAsTempHandle
46 
47   Description:  ハンドルにサウンドを関連付ける
48 
49   Arguments:    sound - 関連付けるサウンド
50 
51   Returns:      None.
52  *---------------------------------------------------------------------------*/
detail_AttachSoundAsTempHandle(internal::WaveSound * sound)53 void WaveSoundHandle::detail_AttachSoundAsTempHandle( internal::WaveSound* sound )
54 {
55     NW_NULL_ASSERT( sound );
56 
57     m_pSound = sound;
58 
59     // 一時ハンドルとしてAttachする
60     if ( m_pSound->IsAttachedTempSpecialHandle() )
61     {
62         m_pSound->DetachTempSpecialHandle();
63     }
64     m_pSound->m_pTempSpecialHandle = this;
65 }
66 
67 /*---------------------------------------------------------------------------*
68   Name:         DetachSound
69 
70   Description:  ハンドルに結びついているサウンドの関連を外す
71 
72   Arguments:    None.
73 
74   Returns:      None.
75  *---------------------------------------------------------------------------*/
DetachSound()76 void WaveSoundHandle::DetachSound()
77 {
78     if ( IsAttachedSound() )
79     {
80         if ( m_pSound->m_pTempSpecialHandle == this ) m_pSound->m_pTempSpecialHandle = NULL;
81     }
82     if ( m_pSound != NULL ) m_pSound = NULL;
83 }
84 
85 } // namespace nw::snd
86 } // namespace nw
87 
88