<commit_before>'use strict';

import _assign from 'lodash.assign';
import _forOwn from 'lodash.forown';

import uuid from 'uuid';
import h from 'virtual-dom/h';

import {secondsToPixels, secondsToSamples} from './utils/conversions';
import extractPeaks from './utils/peaks';
import stateClasses from './track/states';

import CanvasHook from './render/CanvasHook';
import FadeCanvasHook from './render/FadeCanvasHook';

import {FADEIN, FADEOUT} from './utils/fades';

const MAX_CANVAS_WIDTH = 1000;

export default class {

    constructor() {

        this.name = "Untitled";
        this.gain = 1;
        this.fades = {};
        this.peakData = {
            type: "WebAudio",
            mono: false
        };

        this.cueIn = 0;
        this.cueOut = 0;
        this.duration = 0;
        this.startTime = 0;
        this.endTime = 0;
    }

    setEventEmitter(ee) {
        this.ee = ee;
    }

    setName(name) {
        this.name = name;
    }

    setCues(cueIn, cueOut) {
        if (cueOut < cueIn) {
            throw new Error("cue out cannot be less than cue in");
        }

        this.cueIn = cueIn;
        this.cueOut = cueOut;
        this.duration = this.cueOut - this.cueIn;
        this.endTime = this.startTime + this.duration;
    }

    /*
    *   start, end in seconds relative to the entire playlist.
    */
    trim(start, end) {
        let offset = this.getStartTime() + this.cueIn;

        this.setCues(start - offset, end - offset);
    }

    setStartTime(start) {
        this.startTime = start;
        this.endTime = start + this.duration;
    }

    setPlayout(playout) {
        this.playout = playout;
    }

    setEnabledStates(enabledStates={}) {
        let defaultStatesEnabled = {
            'cursor': true,
            'fadein': true,
            'fadeout': true,
            'select': true,
            'shift': true
        };

        this.enabledStates = _assign(defaultStatesEnabled, enabledStates);<commit_msg>Trim functions like Audacity's trim function.<commit_after>'use strict';

import _assign from 'lodash.assign';
import _forOwn from 'lodash.forown';

import uuid from 'uuid';
import h from 'virtual-dom/h';

import {secondsToPixels, secondsToSamples} from './utils/conversions';
import extractPeaks from './utils/peaks';
import stateClasses from './track/states';

import CanvasHook from './render/CanvasHook';
import FadeCanvasHook from './render/FadeCanvasHook';

import {FADEIN, FADEOUT} from './utils/fades';

const MAX_CANVAS_WIDTH = 1000;

export default class {

    constructor() {

        this.name = "Untitled";
        this.gain = 1;
        this.fades = {};
        this.peakData = {
            type: "WebAudio",
            mono: false
        };

        this.cueIn = 0;
        this.cueOut = 0;
        this.duration = 0;
        this.startTime = 0;
        this.endTime = 0;
    }

    setEventEmitter(ee) {
        this.ee = ee;
    }

    setName(name) {
        this.name = name;
    }

    setCues(cueIn, cueOut) {
        if (cueOut < cueIn) {
            throw new Error("cue out cannot be less than cue in");
        }

        this.cueIn = cueIn;
        this.cueOut = cueOut;
        this.duration = this.cueOut - this.cueIn;
        this.endTime = this.startTime + this.duration;
    }

    /*
    *   start, end in seconds relative to the entire playlist.
    */
    trim(start, end) {
        let trackStart = this.getStartTime();
        let trackEnd = this.getEndTime();
        let offset = this.cueIn - trackStart;

        if ((trackStart <= start && trackEnd >= start) ||
            (trackStart <= end && trackEnd >= end)) {

            let cueIn = (start < trackStart) ? trackStart : start;
            let cueOut = (end > trackEnd) ? trackEnd : end;

            this.setCues(cueIn + offset, cueOut + offset);
            if (start > trackStart) {
                this.setStartTime(start);
            }
        }
    }

    setStartTime(start) {
        this.startTime = start;
        this.endTime = start + this.duration;
    }

    setPlayout(playout) {
        this.playout = playout;
    }

    setEnabledStates(enabledStates={}) {
        let defaultStatesEnabled = {
            'cursor': true,
            'fadein': true,
            'fadeout': true,
            'select': true,
            'shift': true
        };

        this.enabledStates = _assign(defaultStatesEnabled, enabledStates);
{'fraction_non_alphanumeric': 0.11919329254475414, 'fraction_numerical': 0.004532064355313846, 'mean_word_length': 1.9804186360567184, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '5672389', 'n_tokens_mistral': 1424, 'n_tokens_neox': 1330, 'n_words': 329}