package turgen.plugin.plturbo;

import java.io.File;
import turgen.Turgen;
import turgen.dtb.DOS2Binary;
import turgen.generator.PulseCrate;
import turgen.playlist.AbstractPlayListItem;
import turgen.plugin.BinaryConvertor;
import turgen.plugin.Plugin;
import turgen.plugin.SimplePlaylistItem;

public class PlTurboBlizzardBinaryConvertor implements BinaryConvertor {


    private final Plugin plugin;
    private final String description;


    public PlTurboBlizzardBinaryConvertor(Plugin p,String description) {
        this.description=description;
        this.plugin=p;
    }

    public boolean acceptsBinary(DOS2Binary bf) {
        return true;
    }

    public boolean acceptsRecorderModification(int recorderModification) {
        if (recorderModification==BinaryConvertor.REC_MOD_PL_BLIZZARD) {
            return true;
        }
        return false;
    }

    public boolean exhaustsRecorderModification(int recorderModification) {
        if (recorderModification==BinaryConvertor.REC_MOD_PL_BLIZZARD) {
            return true;
        }
        return false;
    }

    public int getPilotToneCount(DOS2Binary bf) {

        /*One pilot tone per kilobyte*/
        int ln = bf.getFileStatistics()[0];
        int blocks = ln/1024;
        if ((ln%1024)!=0) blocks++;

        /*One pilot tone for header and one for sync block*/
        return blocks+2;
    }

    public String getDescription() {
        return description;
    }

    public boolean hasLoader() {
        return true;
    }

    public AbstractPlayListItem getPlaylistItem(DOS2Binary bf, String inFile, String outFile, PulseCrate speed,int[] silenceList) {

        

        /*Extract name*/
        File f = new File(inFile);
        String sName = f.getName();

        if (sName.length()>16) sName=sName.substring(0,16);

        SimplePlaylistItem ri = new SimplePlaylistItem(inFile,outFile,speed,sName,silenceList);
        ri.pluginClass=ri.pluginClass=Turgen.pluginManager.getPluginClassName(plugin);

        return ri;

    }

    public PulseCrate[] getSpeeds(int recorderModification) {
        return Turgen.pulseCache.getPulsesForPlugin(plugin);
    }

    public boolean requiresPulses() {
        return true;
    }


}
