1 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; 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 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 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 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 |