<commit_before>import AbstractPlugin from "../registry/AbstractPlugin";
import {
    IPlugin,
    IPluginMetaData,
    Tuple,
    IOscActionDef,
    IState,
    IntermixNote,
    IntermixCtrl,
} from "../registry/interfaces";
/**
 * The builtin synthesizer plugin for intermix.js
 *
 * For API docs of the AudioContext see
 * https://developer.mozilla.org/de/docs/Web/API/AudioContext
 */
export default class DemoSynth extends AbstractPlugin implements IPlugin {
    private static readonly PREFIX = "/intermix/plugin/{UID}/";

    public readonly metaData: IPluginMetaData = {
        type: "instrument",
        name: "Intermix Synth",
        version: "1.0.0",
        authors: "<NAME>",
        desc: "A simple synthesizer",
    };

    public readonly actionDefs: IOscActionDef[] = [
        {
            address: DemoSynth.PREFIX + "envAttack",
            typeTag: ",sff",
            value: ["Envelope Attack", 0.0, 0.0],
            description: "Filter-Envelope Attack",
        },
        {
            address: DemoSynth.PREFIX + "envDecay",
            typeTag: ",sff",
            value: ["Envelope Decay", 0.0, 0.0],
            description: "Filter-Envelope Decay",
        },
    ];

    private myState: IState = {};
    private attack: number;
    private decay: number;
    private filter: BiquadFilterNode;
    private queue: OscillatorNode[] = [];

    constructor(public readonly uid: string, private ac: AudioContext) {
        super();

        // Create a new biquad filter
        this.filter = this.ac.createBiquadFilter();

        // Initial envelope attack value in seconds
        this.attack = 0.1;

        // Initial envelope decay value in seconds
        this.decay = 0.1;

        // Initialize filter
        this.initFilter();
    }

    /**
     * Used by the master registry to inject the state from the store
     * This is ment to be readonly.
     * Never ever manipulate the state from within the plugin!
     */
    public set pluginState(subState: IState) {
        this.myState = subState;
    }

    // list of all audio output nodes
    public get outputs(): AudioNode[] {
        return [this.filter];
    }

    // list of all input nodes, if no inputs, return an empty list
    public get inputs(): AudioNode[] {
        return [];
    }

    // onChange gets called
    // on every state change
    public onChange(changed: Tuple): boolean {
        // console.log(changed);
        switch (changed[0]) {
            case "NOTE":
                const note: IntermixNote = changed[1];
                this.handleNote(note);
                return true;
            case "STOP":
                this.stop();
                return true;
            case "ENV_ATTACK":
                const attack: IntermixCtrl = changed[1];
                this.handleAttack(attack);
                return true;
            case "ENV_DECAY":
                const decay: IntermixCtrl = changed[1];
                this.handleDecay(decay);
                return true;
            default:
                return false;
        }
    }<commit_msg>Synth actions fixed<commit_after>import AbstractPlugin from "../registry/AbstractPlugin";
import {
    IPlugin,
    IPluginMetaData,
    Tuple,
    IOscActionDef,
    IState,
    IntermixNote,
    IntermixCtrl,
} from "../registry/interfaces";
/**
 * The builtin synthesizer plugin for intermix.js
 *
 * For API docs of the AudioContext see
 * https://developer.mozilla.org/de/docs/Web/API/AudioContext
 */
export default class DemoSynth extends AbstractPlugin implements IPlugin {
    private static readonly PREFIX = "/intermix/plugin/{UID}/";

    public readonly metaData: IPluginMetaData = {
        type: "instrument",
        name: "Intermix Synth",
        version: "1.0.0",
        authors: "<NAME>",
        desc: "A simple synthesizer",
    };

    public readonly actionDefs: IOscActionDef[] = [
        {
            address: DemoSynth.PREFIX + "envAttack",
            typeTag: ",sff",
            value: ["Envelope Attack", 0.0, 0.0],
            description: "Filter-Envelope Attack",
        },
        {
            address: DemoSynth.PREFIX + "envDecay",
            typeTag: ",sff",
            value: ["Envelope Decay", 0.0, 0.0],
            description: "Filter-Envelope Decay",
        },
        {
            address: DemoSynth.PREFIX + "stop",
            typeTag: ",N",
            description: "immediately disconnect all nodes from audio output",
        }
    ];

    private myState: IState = {};
    private attack: number;
    private decay: number;
    private filter: BiquadFilterNode;
    private queue: OscillatorNode[] = [];

    constructor(public readonly uid: string, private ac: AudioContext) {
        super();

        // Create a new biquad filter
        this.filter = this.ac.createBiquadFilter();

        // Initial envelope attack value in seconds
        this.attack = 0.1;

        // Initial envelope decay value in seconds
        this.decay = 0.1;

        // Initialize filter
        this.initFilter();
    }

    /**
     * Used by the master registry to inject the state from the store
     * This is ment to be readonly.
     * Never ever manipulate the state from within the plugin!
     */
    public set pluginState(subState: IState) {
        this.myState = subState;
    }

    // list of all audio output nodes
    public get outputs(): AudioNode[] {
        return [this.filter];
    }

    // list of all input nodes, if no inputs, return an empty list
    public get inputs(): AudioNode[] {
        return [];
    }

    // onChange gets called
    // on every state change
    public onChange(changed: Tuple): boolean {
        // console.log(changed);
        switch (changed[0]) {
            case "note":
                const note: IntermixNote = changed[1];
                this.handleNote(note);
                return true;
            case "stop":
                this.stop();
                return true;
            case "envAttack":
                const attack: IntermixCtrl = changed[1];
                this.handleAttack(attack);
                return true;
            case "envDecay":
                const decay: IntermixCtrl = changed[1];
                this.handleDecay(decay);
                return true;
            default:
                return false;
        }
    }
{'fraction_non_alphanumeric': 0.1040617128463476, 'fraction_numerical': 0.005982367758186398, 'mean_word_length': 1.8412343470483006, 'pattern_counts': {'":': 8, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3701939', 'n_tokens_mistral': 1771, 'n_tokens_neox': 1695, 'n_words': 511}