ImportEventParameters.java

package client.teavm.common.parameter.event;

import client.teavm.common.parameter.usage.EventUsageFormatter;
import com.beust.jcommander.IUsageFormatter;
import com.beust.jcommander.JCommander;
import com.beust.jcommander.Parameter;
import com.beust.jcommander.Parameters;
import com.beust.jcommander.internal.Console;
import com.beust.jcommander.internal.DefaultConsole;
import libsidplay.components.printer.IPaper.Outputs;
import server.restful.common.parameter.UsageParameter;
import sidplay.ini.IniDefaults;

import java.util.function.Function;

import static java.lang.Integer.MAX_VALUE;

/**
 * Imported events for I/O capabilities (WebWorker calls JavaScript functions)
 * <p>
 * Purpose is to generate documentation of the JavaScript API on the client side.
 */
@SuppressWarnings({"unused", "FieldMayBeFinal"})
@Parameters(resourceBundle = ImportEventParameters.BUNDLE)
public class ImportEventParameters extends UsageParameter implements IImportEventParameters, IniDefaults {

    public static final String BUNDLE = "client.teavm.common.parameter.event.ImportEventParameters";

    //
    // SharedArrayBuffer version events
    //

    @Parameters(commandNames = EVENT_INIT_CONTROL_BUFFER_SAB, commandDescriptionKey = EVENT_INIT_CONTROL_BUFFER_SAB, resourceBundle = BUNDLE)
    private static class InitControlBufferSABEvent {

        @Parameter(names = CONTROL_BUFFER, descriptionKey = "INIT_CONTROL_BUFFER_SAB_CONTROL_BUFFER", order = 0)
        private int[] controlBuffer;

    }

    @Parameters(commandNames = EVENT_INIT_SAMPLE_BUFFER_SAB, commandDescriptionKey = EVENT_INIT_SAMPLE_BUFFER_SAB, resourceBundle = BUNDLE)
    private static class InitSampleBufferSABEvent {

        @Parameter(names = SAMPLE_BUFFER, descriptionKey = "INIT_SAMPLE_BUFFER_SAB_SAMPLE_BUFFER", order = 0)
        private byte[] sampleBuffer;

    }

    @Parameters(commandNames = EVENT_INIT_FRAME_BUFFER_SAB, commandDescriptionKey = EVENT_INIT_FRAME_BUFFER_SAB, resourceBundle = BUNDLE)
    private static class InitFrameBufferSABEvent {

        @Parameter(names = FRAME_BUFFER, descriptionKey = "INIT_FRAME_BUFFER_SAB_FRAME_BUFFER", order = 0)
        private byte[] frameBuffer;

    }

    @Parameters(commandNames = EVENT_INIT_WHATSSID_SAB, commandDescriptionKey = EVENT_INIT_WHATSSID_SAB, resourceBundle = BUNDLE)
    private static class InitWhatsSidBufferSABEvent {

        @Parameter(names = WHATSSID_BUFFER, descriptionKey = "INIT_WHATSSID_BUFFER_SAB_WHATSSID_BUFFER", order = 0)
        private byte[] whatsSidBuffer;

    }

    @Parameters(commandNames = EVENT_INIT_OSC_BATCH_BUFFER_SAB, commandDescriptionKey = EVENT_INIT_OSC_BATCH_BUFFER_SAB, resourceBundle = BUNDLE)
    private static class InitOscBatchSabEvent {
        @Parameter(names = BUFFER_INDEX, descriptionKey = "INIT_OSC_BATCH_BUFFER_SAB_BUFFER_INDEX", order = 0)
        private int slot;
        @Parameter(names = OSC_BUFFER, descriptionKey = "INIT_OSC_BATCH_BUFFER_SAB_OSC_BUFFER", order = 1)
        private byte[] buffer;
    }

    @Parameters(commandNames = EVENT_SAMPLES_SAB, commandDescriptionKey = EVENT_SAMPLES_SAB, resourceBundle = BUNDLE)
    private static class SamplesSABEvent {
    }

    @Parameters(commandNames = EVENT_FRAME_SAB, commandDescriptionKey = EVENT_FRAME_SAB, resourceBundle = BUNDLE)
    private static class FrameSABEvent {

        @Parameter(names = BUFFER_INDEX, descriptionKey = "FRAME_SAB_BUFFER_INDEX", order = 0)
        private int bufferIndex;

    }

    @Parameters(commandNames = EVENT_WHATSSID_SAB, commandDescriptionKey = EVENT_WHATSSID_SAB, resourceBundle = BUNDLE)
    private static class WhatssidSABEvent {
    }

    @Parameters(commandNames = EVENT_OSC_BATCH_SAB, commandDescriptionKey = EVENT_OSC_BATCH_SAB, resourceBundle = BUNDLE)
    private static class OscBatchSabEvent {
        @Parameter(names = BUFFER_INDEX, descriptionKey = "OSC_BATCH_SAB_BUFFER_INDEX", order = 0)
        private int slot;
        @Parameter(names = LENGTH, descriptionKey = "OSC_BATCH_SAB_LENGTH", order = 1)
        private int length;
    }

    //
    // Normal events
    //

    @Parameters(commandNames = EVENT_SAMPLES, commandDescriptionKey = EVENT_SAMPLES, resourceBundle = BUNDLE)
    private static class SamplesEvent {

        @Parameter(names = ABS_TIME, descriptionKey = "SAMPLES_ABS_TIME", order = 0)
        private long absTime;

        @Parameter(names = LEFT, descriptionKey = "SAMPLES_LEFT", order = 1)
        private float[] left;

        @Parameter(names = RIGHT, descriptionKey = "SAMPLES_RIGHT", order = 2)
        private float[] right;

        @Parameter(names = LENGTH, descriptionKey = "SAMPLES_LENGTH", order = 3)
        private int length;

    }

    @Parameters(commandNames = EVENT_FRAME, commandDescriptionKey = EVENT_FRAME, resourceBundle = BUNDLE)
    private static class FrameEvent {

        @Parameter(names = IMAGE, descriptionKey = "FRAME_IMAGE", order = 0)
        private byte[] image;

    }

    @Parameters(commandNames = EVENT_WHATSSID, commandDescriptionKey = EVENT_WHATSSID, resourceBundle = BUNDLE)
    private static class WhatsSidEvent {

        @Parameter(names = WAV, descriptionKey = "WHATSSID_WAV", order = 0)
        private byte[] wav;

    }

    @Parameters(commandNames = EVENT_OSC_BATCH, commandDescriptionKey = EVENT_OSC_BATCH, resourceBundle = BUNDLE)
    private static class OscBatchEvent {
        @Parameter(names = "buffer", descriptionKey = "OSC_BATCH_BUFFER", order = 0)
        private byte[] buffer;
    }

    @Parameters(commandNames = EVENT_AUDIO_TIMING, commandDescriptionKey = EVENT_AUDIO_TIMING, resourceBundle = BUNDLE)
    private static class AudioTimingEvent {
        @Parameter(names = TIMING, descriptionKey = "AUDIO_TIMING_BUFFER", order = 0)
        private byte[] timing;
    }

    @Parameters(commandNames = EVENT_OSC_SOURCES, commandDescriptionKey = EVENT_OSC_SOURCES, resourceBundle = BUNDLE)
    private static class OscSourcesEvent {
        @Parameter(names = OPL_TYPE, descriptionKey = "OSC_SOURCES_OPL_TYPE", order = 0)
        private int oplType;

        @Parameter(names = GENERATON, descriptionKey = "OSC_SOURCES_GENERATION", order = 1)
        private int generation;

    }

    @Parameters(commandNames = EVENT_SID_WRITE, commandDescriptionKey = EVENT_SID_WRITE, resourceBundle = BUNDLE)
    private static class SidWriteEvent {

        @Parameter(names = SID_NUM, descriptionKey = "SID_WRITE_SID_NUM", order = 0)
        private int sidNum;

        @Parameter(names = ABS_TIME, descriptionKey = "SID_WRITE_ABS_TIME", order = 1)
        private long absTime;

        @Parameter(names = REL_TIME, descriptionKey = "SID_WRITE_REL_TIME", order = 2)
        private int relTime;

        @Parameter(names = ADDR, descriptionKey = "SID_WRITE_ADDR", order = 3)
        private int addr;

        @Parameter(names = VALUE, descriptionKey = "SID_WRITE_VALUE", order = 4)
        private int value;

    }

    @Parameters(commandNames = EVENT_SID_WRITE_BATCH, commandDescriptionKey = EVENT_SID_WRITE_BATCH, resourceBundle = BUNDLE)
    private static class SidWriteBatchEvent {
        @Parameter(names = "version", descriptionKey = "SID_WRITE_BATCH_VERSION", order = 0)
        private int version;
        @Parameter(names = "count", descriptionKey = "SID_WRITE_BATCH_COUNT", order = 1)
        private int count;
        @Parameter(names = "buffer", descriptionKey = "SID_WRITE_BATCH_BUFFER", order = 2)
        private byte[] buffer;
    }

    @Parameters(commandNames = EVENT_MUTE_SET, commandDescriptionKey = EVENT_MUTE_SET, resourceBundle = BUNDLE)
    private static class MuteSetEvent {
        @Parameter(names = SID_NUM, descriptionKey = "MUTE_SET_SID_NUM", order = 0)
        private int sidNum;
        @Parameter(names = VOICE, descriptionKey = "MUTE_SET_VOICE", order = 1)
        private int voice;
        @Parameter(names = VALUE, descriptionKey = "MUTE_SET_VALUE", order = 2)
        private boolean value;
    }

    @Parameters(commandNames = EVENT_WARP_STATE, commandDescriptionKey = EVENT_WARP_STATE, resourceBundle = BUNDLE)
    private static class WarpStateEvent {

        @Parameter(names = ENABLED, descriptionKey = "WARP_STATE_ENABLED", order = 0)
        private boolean enabled;

    }

    @Parameters(commandNames = EVENT_TIMER_END, commandDescriptionKey = EVENT_TIMER_END, resourceBundle = BUNDLE)
    private static class TimerEndEvent {

        @Parameter(names = END, descriptionKey = "TIMER_END_END", order = 0)
        private double end;

    }

    @Parameters(commandNames = EVENT_PRINTER, commandDescriptionKey = EVENT_PRINTER, resourceBundle = BUNDLE)
    private static class PrinterEvent {

        @Parameter(names = OUTPUT, descriptionKey = "PRINTER_OUTPUT", order = 0)
        private Outputs output;

    }

    @Parameters(commandNames = "GOT_GEORAM_IMAGE", commandDescriptionKey = "GOT_GEORAM_IMAGE", resourceBundle = BUNDLE)
    private static class GeoRAMImageEvent {

        @Parameter(names = "requestId", descriptionKey = "GOT_GEORAM_IMAGE_REQUEST_ID", order = 0)
        private int requestId;

        @Parameter(names = "contents", descriptionKey = "GOT_GEORAM_IMAGE_CONTENTS", order = 1)
        private byte[] contents;

    }

    @Parameters(commandNames = "GEORAM_INSERTED", commandDescriptionKey = "GEORAM_INSERTED", resourceBundle = BUNDLE)
    private static class GeoRAMInsertedEvent {

        @Parameter(names = "requestId", descriptionKey = "GEORAM_INSERTED_REQUEST_ID", order = 0)
        private int requestId;

        @Parameter(names = "success", descriptionKey = "GEORAM_INSERTED_SUCCESS", order = 1)
        private boolean success;

    }

    @Parameters(commandNames = "INSPECTION", commandDescriptionKey = "INSPECTION", resourceBundle = BUNDLE)
    private static class InspectionEvent {

        @Parameter(names = "sequence", descriptionKey = "INSPECTION_SEQUENCE", order = 0)
        private int sequence;

        @Parameter(names = "json", descriptionKey = "INSPECTION_JSON", order = 1)
        private String json;

    }

    @Parameters(commandNames = "INSPECTION_ERROR", commandDescriptionKey = "INSPECTION_ERROR", resourceBundle = BUNDLE)
    private static class InspectionErrorEvent {

        @Parameter(names = "message", descriptionKey = "INSPECTION_ERROR_MESSAGE", order = 0)
        private String message;

    }

    public static void usage(Console console) {
        usage(console, jCommander -> new EventUsageFormatter(jCommander, false));
    }

    public static void usage(Console console, Function<JCommander, IUsageFormatter> eventUsageFormatter) {
        JCommander jCommander = JCommander.newBuilder().addObject(new ImportEventParameters())

                //
                // SharedArrayBuffer version events
                //

                .addCommand(new InitControlBufferSABEvent())
                //
                .addCommand(new InitSampleBufferSABEvent())
                //
                .addCommand(new InitFrameBufferSABEvent())
                //
                .addCommand(new InitWhatsSidBufferSABEvent())
                //
                .addCommand(new SamplesSABEvent())
                //
                .addCommand(new FrameSABEvent())
                //
                .addCommand(new WhatssidSABEvent())
                //
                .addCommand(new InitOscBatchSabEvent())
                //
                .addCommand(new OscBatchSabEvent())

                //
                // Normal version events
                //

                .addCommand(new SamplesEvent())
                //
                .addCommand(new FrameEvent())
                //
                .addCommand(new OscBatchEvent())
                //
                .addCommand(new AudioTimingEvent())
                //
                .addCommand(new OscSourcesEvent())
                //
                .addCommand(new WhatsSidEvent())
                //
                .addCommand(new SidWriteEvent())
                //
                .addCommand(new SidWriteBatchEvent())
                //
                .addCommand(new MuteSetEvent())
                //
                .addCommand(new WarpStateEvent())

                .addCommand(new TimerEndEvent())
                //
                .addCommand(new PrinterEvent())
                //
                .addCommand(new GeoRAMImageEvent())
                //
                .addCommand(new GeoRAMInsertedEvent())
                //
                .addCommand(new InspectionEvent())
                //
                .addCommand(new InspectionErrorEvent())

                //
                .columnSize(MAX_VALUE).programName(ImportEventParameters.class.toString()).console(console).build();

        jCommander.setUsageFormatter(eventUsageFormatter.apply(jCommander));
        jCommander.usage();
    }

    public static void main(String[] args) {
        usage(new DefaultConsole());
    }

}