001: /*
002: * $Id: SoundInfo.java,v 1.2 2002/02/15 23:44:28 skavish Exp $
003: *
004: * ===========================================================================
005: *
006: * The JGenerator Software License, Version 1.0
007: *
008: * Copyright (c) 2000 Dmitry Skavish (skavish@usa.net). All rights reserved.
009: *
010: * Redistribution and use in source and binary forms, with or without
011: * modification, are permitted provided that the following conditions are met:
012: *
013: * 1. Redistributions of source code must retain the above copyright
014: * notice, this list of conditions and the following disclaimer.
015: *
016: * 2. Redistributions in binary form must reproduce the above copyright
017: * notice, this list of conditions and the following disclaimer in
018: * the documentation and/or other materials provided with the
019: * distribution.
020: *
021: * 3. The end-user documentation included with the redistribution, if
022: * any, must include the following acknowlegement:
023: * "This product includes software developed by Dmitry Skavish
024: * (skavish@usa.net, http://www.flashgap.com/)."
025: * Alternately, this acknowlegement may appear in the software itself,
026: * if and wherever such third-party acknowlegements normally appear.
027: *
028: * 4. The name "The JGenerator" must not be used to endorse or promote
029: * products derived from this software without prior written permission.
030: * For written permission, please contact skavish@usa.net.
031: *
032: * 5. Products derived from this software may not be called "The JGenerator"
033: * nor may "The JGenerator" appear in their names without prior written
034: * permission of Dmitry Skavish.
035: *
036: * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
037: * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
038: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
039: * DISCLAIMED. IN NO EVENT SHALL DMITRY SKAVISH OR THE OTHER
040: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
041: * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
042: * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
043: * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
044: * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
045: * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
046: * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
047: * SUCH DAMAGE.
048: *
049: */
050:
051: package org.openlaszlo.iv.flash.api.sound;
052:
053: import java.io.*;
054: import org.openlaszlo.iv.flash.parser.*;
055: import org.openlaszlo.iv.flash.util.*;
056: import org.openlaszlo.iv.flash.api.*;
057:
058: public final class SoundInfo extends FlashItem {
059:
060: public static final int SYNC_NO_MULTIPLE = 0x10;
061: public static final int SYNC_STOP = 0x20;
062: public static final int HAS_ENVELOPE = 0x08;
063: public static final int HAS_LOOPS = 0x04;
064: public static final int HAS_OUT_POINT = 0x02;
065: public static final int HAS_IN_POINT = 0x01;
066:
067: private int flags;
068: private int inPoint;
069: private int outPoint;
070: private int loopCount;
071: private IVVector envelopes;
072:
073: public SoundInfo() {
074: }
075:
076: public static SoundInfo parse(Parser p) {
077: SoundInfo s = new SoundInfo();
078: int flags = s.flags = p.getUByte();
079: if ((flags & HAS_IN_POINT) != 0) {
080: s.inPoint = p.getUDWord();
081: }
082: if ((flags & HAS_OUT_POINT) != 0) {
083: s.outPoint = p.getUDWord();
084: }
085: if ((flags & HAS_LOOPS) != 0) {
086: s.loopCount = p.getUWord();
087: }
088: if ((flags & HAS_ENVELOPE) != 0) {
089: int nPoints = p.getUByte();
090: s.envelopes = new IVVector(nPoints);
091: for (int i = 0; i < nPoints; i++) {
092: s.envelopes.addElement(SoundEnvelope.parse(p));
093: }
094: }
095: return s;
096: }
097:
098: public static SoundInfo newSoundInfo(int flags) {
099:
100: SoundInfo soundInfo = new SoundInfo();
101:
102: soundInfo.flags = flags;
103:
104: soundInfo.envelopes = new IVVector(0);
105:
106: return soundInfo;
107:
108: }
109:
110: public int length() {
111:
112: int length = 1; // Flags
113:
114: if ((flags & HAS_IN_POINT) != 0) {
115: length += 4;
116: }
117:
118: if ((flags & HAS_OUT_POINT) != 0) {
119: length += 4;
120: }
121:
122: if ((flags & HAS_LOOPS) != 0) {
123: length += 2;
124: }
125:
126: if ((flags & HAS_ENVELOPE) != 0) {
127: length += (1 + (8 * envelopes.size()));
128: }
129:
130: return length;
131:
132: }
133:
134: public void write(FlashOutput fob) {
135: fob.writeByte(flags);
136: if ((flags & HAS_IN_POINT) != 0) {
137: fob.writeDWord(inPoint);
138: }
139: if ((flags & HAS_OUT_POINT) != 0) {
140: fob.writeDWord(outPoint);
141: }
142: if ((flags & HAS_LOOPS) != 0) {
143: fob.writeWord(loopCount);
144: }
145: if ((flags & HAS_ENVELOPE) != 0) {
146: int nPoints = envelopes.size();
147: fob.writeByte(nPoints);
148: envelopes.write(fob);
149: }
150: }
151:
152: public void printContent(PrintStream out, String indent) {
153: out.println(indent + "SoundInfo:");
154: }
155:
156: protected FlashItem copyInto(FlashItem item, ScriptCopier copier) {
157: super .copyInto(item, copier);
158: ((SoundInfo) item).flags = flags;
159: ((SoundInfo) item).inPoint = inPoint;
160: ((SoundInfo) item).outPoint = outPoint;
161: ((SoundInfo) item).loopCount = loopCount;
162: ((SoundInfo) item).envelopes = envelopes != null ? envelopes
163: .getCopy(copier) : null;
164: return item;
165: }
166:
167: public FlashItem getCopy(ScriptCopier copier) {
168: return copyInto(new SoundInfo(), copier);
169: }
170:
171: /**
172: * Sound Envelope
173: */
174: public static class SoundEnvelope extends FlashItem {
175: public int mark44;
176: public int level0;
177: public int level1;
178:
179: public SoundEnvelope() {
180: }
181:
182: public static SoundEnvelope parse(Parser p) {
183: SoundEnvelope s = new SoundEnvelope();
184: s.mark44 = p.getUDWord();
185: s.level0 = p.getUWord();
186: s.level1 = p.getUWord();
187: return s;
188: }
189:
190: public void write(FlashOutput fob) {
191: fob.writeDWord(mark44);
192: fob.writeWord(level0);
193: fob.writeWord(level1);
194: }
195:
196: public void printContent(PrintStream out, String indent) {
197: }
198:
199: protected FlashItem copyInto(FlashItem item, ScriptCopier copier) {
200: ((SoundEnvelope) item).mark44 = mark44;
201: ((SoundEnvelope) item).level0 = level0;
202: ((SoundEnvelope) item).level1 = level1;
203: return item;
204: }
205:
206: public FlashItem getCopy(ScriptCopier copier) {
207: return copyInto(new SoundEnvelope(), copier);
208: }
209: }
210:
211: }
|