package turgen.plugin.btape;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import turgen.generator.PulseCrate;
import turgen.playlist.AbstractPlayListItem;
import turgen.plugin.SimplePlaylistItem;



public class BTapePlayListItem extends SimplePlaylistItem {
    
    boolean longGaps;
    boolean doubleBlocks;
    
    public BTapePlayListItem() {
        
    }
    
    public BTapePlayListItem(String inF,String outF,PulseCrate speed,String fname,int[] sList,boolean longGaps,boolean doubleBlocks,int loader) {
        this.inFile=inF;
        this.outFile=outF;
        this.pulses=speed;
        this.silenceList=sList;
        
        this.fname=fname;
        this.longGaps=longGaps;
        this.doubleBlocks=doubleBlocks;
        this.loader=loader;
        
    }
    
    public String toString() {
        String ldr=" +BL";
        char[] mode = new char[2];
        mode[0]='S';
        mode[1]='S';

        if (longGaps==true) mode[0]='L';
        if (doubleBlocks==true) mode[1]='D';
        if (loader==BTapePlugin.BL_NONE) ldr="";
        
        return fname+" ["+new String(mode)+"]"+ldr;
    }
    
    public boolean validate() {
        if (this.inFile==null) return false;
        if (this.outFile==null) this.outFile="";
        if (this.fname==null) this.fname="NONAME";
        if (this.pulses==null) return false;
        if (this.silenceList==null) silenceList=new int[0];
        if (this.loader<0 || this.loader>BTapePlugin.BL_NANOBTAPE_UR) this.loader=BTapePlugin.BL_NONE;
        return true;
    }
    
    public AbstractPlayListItem getClonedCopy() {
        int[] silenceListCopy = (int[])this.silenceList.clone();
        PulseCrate pulsesCopy = pulses.getCopy();
        BTapePlayListItem item = new BTapePlayListItem(inFile, outFile, pulsesCopy,fname, silenceListCopy,longGaps,doubleBlocks,loader);
        copyBasics(item);
        return item;
    }
    
    public void saveToStream(DataOutputStream dos) throws Exception {
        //saveBasics(dos);
        super.saveToStream(dos);
        dos.writeBoolean(longGaps);
        dos.writeBoolean(doubleBlocks);
        
    }
    
    public void loadFromStream(DataInputStream dis,int version) throws Exception {
        //loadBasics(dis);
        super.loadFromStream(dis, version);
        longGaps=dis.readBoolean();
        doubleBlocks=dis.readBoolean();
        
    }

}
