KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openlaszlo > iv > flash > api > sound > SoundInfo


1 /*
2  * $Id: SoundInfo.java,v 1.2 2002/02/15 23:44:28 skavish Exp $
3  *
4  * ===========================================================================
5  *
6  * The JGenerator Software License, Version 1.0
7  *
8  * Copyright (c) 2000 Dmitry Skavish (skavish@usa.net). All rights reserved.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions are met:
12  *
13  * 1. Redistributions of source code must retain the above copyright
14  * notice, this list of conditions and the following disclaimer.
15  *
16  * 2. Redistributions in binary form must reproduce the above copyright
17  * notice, this list of conditions and the following disclaimer in
18  * the documentation and/or other materials provided with the
19  * distribution.
20  *
21  * 3. The end-user documentation included with the redistribution, if
22  * any, must include the following acknowlegement:
23  * "This product includes software developed by Dmitry Skavish
24  * (skavish@usa.net, http://www.flashgap.com/)."
25  * Alternately, this acknowlegement may appear in the software itself,
26  * if and wherever such third-party acknowlegements normally appear.
27  *
28  * 4. The name "The JGenerator" must not be used to endorse or promote
29  * products derived from this software without prior written permission.
30  * For written permission, please contact skavish@usa.net.
31  *
32  * 5. Products derived from this software may not be called "The JGenerator"
33  * nor may "The JGenerator" appear in their names without prior written
34  * permission of Dmitry Skavish.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL DMITRY SKAVISH OR THE OTHER
40  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  *
49  */

50
51 package org.openlaszlo.iv.flash.api.sound;
52
53 import java.io.*;
54 import org.openlaszlo.iv.flash.parser.*;
55 import org.openlaszlo.iv.flash.util.*;
56 import org.openlaszlo.iv.flash.api.*;
57
58 public final class SoundInfo extends FlashItem {
59
60     public static final int SYNC_NO_MULTIPLE = 0x10;
61     public static final int SYNC_STOP = 0x20;
62     public static final int HAS_ENVELOPE = 0x08;
63     public static final int HAS_LOOPS = 0x04;
64     public static final int HAS_OUT_POINT = 0x02;
65     public static final int HAS_IN_POINT = 0x01;
66
67     private int flags;
68     private int inPoint;
69     private int outPoint;
70     private int loopCount;
71     private IVVector envelopes;
72
73     public SoundInfo() {}
74
75     public static SoundInfo parse( Parser p ) {
76         SoundInfo s = new SoundInfo();
77         int flags = s.flags = p.getUByte();
78         if( (flags&HAS_IN_POINT)!=0 ) {
79             s.inPoint = p.getUDWord();
80         }
81         if( (flags&HAS_OUT_POINT)!=0 ) {
82             s.outPoint = p.getUDWord();
83         }
84         if( (flags&HAS_LOOPS)!=0 ) {
85             s.loopCount = p.getUWord();
86         }
87         if( (flags&HAS_ENVELOPE)!=0 ) {
88             int nPoints = p.getUByte();
89             s.envelopes = new IVVector(nPoints);
90             for( int i=0; i<nPoints; i++ ) {
91                 s.envelopes.addElement( SoundEnvelope.parse(p) );
92             }
93         }
94         return s;
95     }
96
97     public static SoundInfo newSoundInfo( int flags ) {
98
99         SoundInfo soundInfo = new SoundInfo();
100
101         soundInfo.flags = flags;
102
103         soundInfo.envelopes = new IVVector( 0 );
104
105         return soundInfo;
106
107     }
108
109     public int length() {
110
111         int length = 1; // Flags
112

113         if ( ( flags & HAS_IN_POINT) != 0 ) { length += 4; }
114
115         if ( ( flags & HAS_OUT_POINT ) != 0 ) { length += 4; }
116
117         if ( ( flags & HAS_LOOPS ) !=0 ) { length += 2; }
118
119         if ( ( flags & HAS_ENVELOPE ) != 0 ) { length += ( 1 + ( 8 * envelopes.size() ) ); }
120
121         return length;
122
123     }
124
125     public void write( FlashOutput fob ) {
126         fob.writeByte(flags);
127         if( (flags&HAS_IN_POINT)!=0 ) {
128             fob.writeDWord(inPoint);
129         }
130         if( (flags&HAS_OUT_POINT)!=0 ) {
131             fob.writeDWord(outPoint);
132         }
133         if( (flags&HAS_LOOPS)!=0 ) {
134             fob.writeWord(loopCount);
135         }
136         if( (flags&HAS_ENVELOPE)!=0 ) {
137             int nPoints = envelopes.size();
138             fob.writeByte(nPoints);
139             envelopes.write(fob);
140         }
141     }
142
143     public void printContent( PrintStream out, String JavaDoc indent ) {
144         out.println( indent+"SoundInfo:" );
145     }
146
147     protected FlashItem copyInto( FlashItem item, ScriptCopier copier ) {
148         super.copyInto( item, copier );
149         ((SoundInfo)item).flags = flags;
150         ((SoundInfo)item).inPoint = inPoint;
151         ((SoundInfo)item).outPoint = outPoint;
152         ((SoundInfo)item).loopCount = loopCount;
153         ((SoundInfo)item).envelopes = envelopes!=null? envelopes.getCopy(copier): null;
154         return item;
155     }
156
157     public FlashItem getCopy( ScriptCopier copier ) {
158         return copyInto( new SoundInfo(), copier );
159     }
160
161     /**
162      * Sound Envelope
163      */

164     public static class SoundEnvelope extends FlashItem {
165         public int mark44;
166         public int level0;
167         public int level1;
168         public SoundEnvelope() {}
169
170         public static SoundEnvelope parse( Parser p ) {
171             SoundEnvelope s = new SoundEnvelope();
172             s.mark44 = p.getUDWord();
173             s.level0 = p.getUWord();
174             s.level1 = p.getUWord();
175             return s;
176         }
177         public void write( FlashOutput fob ) {
178             fob.writeDWord(mark44);
179             fob.writeWord(level0);
180             fob.writeWord(level1);
181         }
182         public void printContent( PrintStream out, String JavaDoc indent ) {}
183
184         protected FlashItem copyInto( FlashItem item, ScriptCopier copier ) {
185             ((SoundEnvelope)item).mark44 = mark44;
186             ((SoundEnvelope)item).level0 = level0;
187             ((SoundEnvelope)item).level1 = level1;
188             return item;
189         }
190         public FlashItem getCopy( ScriptCopier copier ) {
191             return copyInto( new SoundEnvelope(), copier );
192         }
193     }
194
195 }
196
197
Popular Tags