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;

public class PlHardTurboBinaryConvertor implements BinaryConvertor {

    private Plugin plugin;
    private String description;
    private int binaryLoader;

    public PlHardTurboBinaryConvertor(Plugin p,String description,int binaryLoader) {
        this.description=description;
        this.plugin=p;
        this.binaryLoader=binaryLoader;
    }


    public boolean acceptsBinary(DOS2Binary bf) {
        
        if (binaryLoader==PlHardTurboPlugin.BL_NONE) {
            return true;
        }
        else {
            if (bf.coversMemory(1999, 2408)) return false;
        }
        return true;
    }

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

    public boolean exhaustsRecorderModification(int recorderModification) {
        return acceptsRecorderModification(recorderModification);
    }

    public int getPilotToneCount(DOS2Binary bf) {

        return bf.getTotalSegmentCount()*2+2;

    }

    public String getDescription() {
        return description;
    }

    public boolean hasLoader() {
        return true;
    }

    public AbstractPlayListItem getPlaylistItem(DOS2Binary bf, String inFile, String outFile, PulseCrate speed) {

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

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

        PlHardTurboPlaylistItem ri = new PlHardTurboPlaylistItem(inFile,outFile,speed,sName,binaryLoader,new int[0]);
        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;
    }


}
