FileDocCategorySizeDatePackage
SYTCID3V2Frame.javaAPI Docjid3 0.4610498Sun Feb 06 18:11:16 GMT 2005org.blinkenlights.jid3.v2

SYTCID3V2Frame

public class SYTCID3V2Frame extends ID3V2Frame
Frame containing synchronized tempo codes.
author
paul

Fields Summary
private TimestampFormat
m_oTimestampFormat
private SortedMap
m_oTempoChangeMap
Constructors Summary
public SYTCID3V2Frame(TimestampFormat oTimestampFormat)
Creates a new instance of SYTCID3V2Frame.

param
oTimestampFormat the timestamp format used in this frame
throws
ID3Exception if oTimestampFormat is null

    
                              
      
         
    
        if (oTimestampFormat == null)
        {
            throw new ID3Exception("Timestamp cannot be null in SYTC frame.");
        }
        m_oTimestampFormat = oTimestampFormat;
        m_oTempoChangeMap = new TreeMap();
    
public SYTCID3V2Frame(InputStream oIS)

        try
        {
            ID3DataInputStream oFrameDataID3DIS = new ID3DataInputStream(oIS);
            
            // timestamp format
            m_oTimestampFormat = new TimestampFormat((byte)oFrameDataID3DIS.readUnsignedByte());
            
            // tempo changes
            m_oTempoChangeMap = new TreeMap();
            while (oFrameDataID3DIS.available() > 0)
            {
                // one byte if < 255, or sum of two bytes if >= 255
                int iBeatsPerMinute = oFrameDataID3DIS.readUnsignedByte();
                if (iBeatsPerMinute == 255)
                {
                    iBeatsPerMinute += oFrameDataID3DIS.readUnsignedByte();
                }
                int iTimestamp = oFrameDataID3DIS.readBE32();
                
                m_oTempoChangeMap.put(new Integer(iTimestamp), new Integer(iBeatsPerMinute));
            }
        }
        catch (Exception e)
        {
            throw new InvalidFrameID3Exception(e);
        }
    
Methods Summary
public voidaccept(ID3Visitor oID3Visitor)

        oID3Visitor.visitSYTCID3V2Frame(this);
    
public voidaddTempoChange(org.blinkenlights.jid3.v2.SYTCID3V2Frame$TempoChange oTempoChange)
Add a tempo change to the frame.

param
oTempoChange the tempo change to be added to this frame
throws
ID3Exception if oTempoChange is null, or if a sync entry for this timestamp already exists in this frame

        if (oTempoChange == null)
        {
            throw new ID3Exception("TempoChange cannot be null.");
        }
        if (m_oTempoChangeMap.keySet().contains(new Integer(oTempoChange.getTimestamp())))
        {
            throw new ID3Exception("SYTC frame already contains a tempo change for timestamp " + oTempoChange.getTimestamp() + ".");
        }
        m_oTempoChangeMap.put(new Integer(oTempoChange.getTimestamp()), new Integer(oTempoChange.getBeatsPerMinute()));
    
public booleanequals(java.lang.Object oOther)

        if ((oOther == null) || (!(oOther instanceof SYTCID3V2Frame)))
        {
            return false;
        }
        
        SYTCID3V2Frame oOtherSYTC = (SYTCID3V2Frame)oOther;

        return (m_oTimestampFormat.equals(oOtherSYTC.m_oTimestampFormat) &&
                m_oTempoChangeMap.equals(oOtherSYTC.m_oTempoChangeMap));
    
protected byte[]getFrameId()

        return "SYTC".getBytes();
    
public org.blinkenlights.jid3.v2.SYTCID3V2Frame$TempoChangegetTempoChange(int iTimestamp)
Get a tempo change from this frame.

param
iTimestamp the timestamp for which the sync entry should be returned
return
the tempo change object matching the specified timestamp, or null if no matching tiemstamp exists

        if (m_oTempoChangeMap.keySet().contains(new Integer(iTimestamp)))
        {
            try
            {
                return new TempoChange(((Integer)m_oTempoChangeMap.get(new Integer(iTimestamp))).intValue(), iTimestamp);
            }
            catch (Exception e) { return null; }    // we've already created this object, so this can't happen
        }
        else
        {
            return null;
        }
    
public org.blinkenlights.jid3.v2.SYTCID3V2Frame$TempoChangeremoveTempoChange(int iTimestamp)
Remove a tempo change from this frame.

param
iTimestamp the timestamp for which the tempo change is to be removed
return
the previously set sync entry for this timestamp, or null if no tempo change was set for this timestamp

        if (m_oTempoChangeMap.keySet().contains(new Integer(iTimestamp)))
        {
            try
            {
                return new TempoChange(((Integer)m_oTempoChangeMap.remove(new Integer(iTimestamp))).intValue(), iTimestamp);
            }
            catch (Exception e) { return null; }    // we've already created this object, so this can't happen
        }
        else
        {
            return null;
        }
    
public java.lang.StringtoString()

        StringBuffer sbText = new StringBuffer();
        sbText.append("Synchronized tempo codes: Timestamp format=[" + m_oTimestampFormat.getValue() + "]");
        Iterator oIter = m_oTempoChangeMap.keySet().iterator();
        while (oIter.hasNext())
        {
            Integer oTimestamp = (Integer)oIter.next();
            Integer oBeatsPerMinute = (Integer)m_oTempoChangeMap.get(oTimestamp);
            sbText.append(" TempoChange(" + oTimestamp.intValue() + ", BPM=" + oBeatsPerMinute.intValue() + ")");
        }
        
        return sbText.toString();
    
protected voidwriteBody(ID3DataOutputStream oIDOS)

        oIDOS.write(m_oTimestampFormat.getValue());
        // tempo changes
        Iterator oIter = m_oTempoChangeMap.keySet().iterator();
        while (oIter.hasNext())
        {
            Integer oTimestamp = (Integer)oIter.next();
            // beats per minute (one byte if < 255, sum of two bytes if >= 255)
            Integer oBeatsPerMinute = (Integer)m_oTempoChangeMap.get(oTimestamp);
            int iBeatsPerMinute = oBeatsPerMinute.intValue();
            if (iBeatsPerMinute >= 255)
            {
                oIDOS.write(255);
                oIDOS.write(iBeatsPerMinute - 255);
            }
            else
            {
                oIDOS.write(iBeatsPerMinute);
            }
            oIDOS.writeBE32(oTimestamp.intValue()); // timestamp
        }