1 /*---------------------------------------------------------------------------*
2   Project:  NintendoWare
3   File:     snd_SequenceSoundFile.cpp
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 #include "precompiled.h"
17 
18 #include <nw/snd/snd_SequenceSoundFile.h>
19 #include <nw/snd/snd_ElementType.h>
20 #include <cstring>      // strlen, strncmp
21 
22 namespace nw {
23 namespace snd {
24 namespace internal {
25 
26 //
27 // SequenceSoundFile::FileHeader
28 //
GetDataBlock() const29 const SequenceSoundFile::DataBlock* SequenceSoundFile::FileHeader::GetDataBlock() const
30 {
31     return reinterpret_cast<const DataBlock*>( GetBlock( ElementType_SequenceSoundFile_DataBlock ) );
32 }
GetLabelBlock() const33 const SequenceSoundFile::LabelBlock* SequenceSoundFile::FileHeader::GetLabelBlock() const
34 {
35     return reinterpret_cast<const LabelBlock*>( GetBlock( ElementType_SequenceSoundFile_LabelBlock ) );
36 }
37 
38 
39 //
40 // SequenceSoundFile::LabelBlockBody
41 //
42 
GetLabelInfo(int index) const43 const SequenceSoundFile::LabelInfo* SequenceSoundFile::LabelBlockBody::GetLabelInfo( int index ) const
44 {
45     NW_ASSERT( index < GetLabelCount() );
46 
47     return reinterpret_cast<const LabelInfo*>(
48             labelInfoReferenceTable.GetReferedItem( index ) );
49 }
50 
GetLabel(int index) const51 const char* SequenceSoundFile::LabelBlockBody::GetLabel( int index ) const
52 {
53     const LabelInfo* labelInfo = GetLabelInfo( index );
54     return labelInfo->label;
55 }
56 
GetLabelByOffset(u32 offset) const57 const char* SequenceSoundFile::LabelBlockBody::GetLabelByOffset( u32 offset ) const
58 {
59     // 線形探索
60     for ( int i = 0; i < GetLabelCount(); i++ )
61     {
62         const LabelInfo* labelInfo = GetLabelInfo( i );
63         if ( labelInfo->referToSequenceData.offset == offset )
64         {
65             return labelInfo->label;
66         }
67     }
68     return NULL;
69 }
70 
GetOffset(int index,u32 * offsetPtr) const71 bool SequenceSoundFile::LabelBlockBody::GetOffset( int index, u32* offsetPtr ) const
72 {
73     const LabelInfo* labelInfo = GetLabelInfo( index );
74     *offsetPtr = labelInfo->referToSequenceData.offset;
75     return true;
76 }
77 
GetOffsetByLabel(const char * label,u32 * offsetPtr) const78 bool SequenceSoundFile::LabelBlockBody::GetOffsetByLabel( const char* label, u32* offsetPtr ) const
79 {
80     const std::size_t labelLength = std::strlen( label );
81 
82     // 線形探索
83     for ( int i = 0; i < GetLabelCount(); i++ )
84     {
85         const LabelInfo* labelInfo = GetLabelInfo( i );
86         if ( std::strncmp( label, labelInfo->label, labelLength ) == 0 )
87         {
88             *offsetPtr = labelInfo->referToSequenceData.offset;
89             return true;
90         }
91     }
92     return false;
93 }
94 
95 
96 } // namespace nw::snd::internal
97 } // namespace nw::snd
98 } // namespace nw
99 
100