1 /*---------------------------------------------------------------------------*
2 Project: NintendoWare
3 File: snd_SequenceSoundFile.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_SequenceSoundFile.h>
21 #include <nw/snd/snd_ElementType.h>
22 #include <cstring> // strlen, strncmp
23
24 namespace nw {
25 namespace snd {
26 namespace internal {
27
28 //
29 // SequenceSoundFile::FileHeader
30 //
GetDataBlock() const31 const SequenceSoundFile::DataBlock* SequenceSoundFile::FileHeader::GetDataBlock() const
32 {
33 return reinterpret_cast<const DataBlock*>( GetBlock( ElementType_SequenceSoundFile_DataBlock ) );
34 }
GetLabelBlock() const35 const SequenceSoundFile::LabelBlock* SequenceSoundFile::FileHeader::GetLabelBlock() const
36 {
37 return reinterpret_cast<const LabelBlock*>( GetBlock( ElementType_SequenceSoundFile_LabelBlock ) );
38 }
39
40
41 //
42 // SequenceSoundFile::LabelBlockBody
43 //
44
GetLabelInfo(int index) const45 const SequenceSoundFile::LabelInfo* SequenceSoundFile::LabelBlockBody::GetLabelInfo( int index ) const
46 {
47 NW_ASSERT( index < GetLabelCount() );
48
49 return reinterpret_cast<const LabelInfo*>(
50 labelInfoReferenceTable.GetReferedItem( index ) );
51 }
52
GetLabel(int index) const53 const char* SequenceSoundFile::LabelBlockBody::GetLabel( int index ) const
54 {
55 const LabelInfo* labelInfo = GetLabelInfo( index );
56 return labelInfo->label;
57 }
58
GetLabelByOffset(u32 offset) const59 const char* SequenceSoundFile::LabelBlockBody::GetLabelByOffset( u32 offset ) const
60 {
61 // 線形探索
62 for ( int i = 0; i < GetLabelCount(); i++ )
63 {
64 const LabelInfo* labelInfo = GetLabelInfo( i );
65 if ( labelInfo->referToSequenceData.offset == offset )
66 {
67 return labelInfo->label;
68 }
69 }
70 return NULL;
71 }
72
GetOffset(int index,u32 * offsetPtr) const73 bool SequenceSoundFile::LabelBlockBody::GetOffset( int index, u32* offsetPtr ) const
74 {
75 const LabelInfo* labelInfo = GetLabelInfo( index );
76 *offsetPtr = labelInfo->referToSequenceData.offset;
77 return true;
78 }
79
GetOffsetByLabel(const char * label,u32 * offsetPtr) const80 bool SequenceSoundFile::LabelBlockBody::GetOffsetByLabel( const char* label, u32* offsetPtr ) const
81 {
82 const std::size_t labelLength = std::strlen( label );
83
84 // 線形探索
85 for ( int i = 0; i < GetLabelCount(); i++ )
86 {
87 const LabelInfo* labelInfo = GetLabelInfo( i );
88 if ( std::strncmp( label, labelInfo->label, labelLength ) == 0 )
89 {
90 *offsetPtr = labelInfo->referToSequenceData.offset;
91 return true;
92 }
93 }
94 return false;
95 }
96
97
98 } // namespace nw::snd::internal
99 } // namespace nw::snd
100 } // namespace nw
101
102