Ignore:
Timestamp:
2021-01-15T15:29:05+13:00 (3 years ago)
Author:
davidb
Message:

Next step in development of spectrum renderer: now inherits from MultiCanvas

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs3-extensions/mars-src/trunk/src/wavesurfer-renderer/drawer.spectrummulticanvas.js

    r34668 r34669  
    1 import Drawer from './drawer';
     1import MultiCanvas from './drawer.multicanvas';
    22import * as util from './util';
    33import CanvasEntry from './drawer.canvasentry';
     
    228228 * on the zoom level.
    229229 */
    230 export default class SpectrumMultiCanvas extends Drawer {
     230export default class SpectrumMultiCanvas extends MultiCanvas {
    231231    /**
    232232     * @param {HTMLElement} container The container node of the wavesurfer instance
     
    235235    constructor(container, params) {
    236236        super(container, params);
    237 
    238         /**
    239          * @type {number}
    240          */
    241         this.maxCanvasWidth = params.maxCanvasWidth;
    242 
    243         /**
    244          * @type {number}
    245          */
    246         this.maxCanvasElementWidth = Math.round(
    247             params.maxCanvasWidth / params.pixelRatio
    248         );
    249 
    250         /**
    251          * Whether or not the progress wave is rendered. If the `waveColor`
    252          * and `progressColor` are the same color it is not.
    253          *
    254          * @type {boolean}
    255          */
    256         this.hasProgressCanvas = params.waveColor != params.progressColor;
    257 
    258         /**
    259          * @type {number}
    260          */
    261         this.halfPixel = 0.5 / params.pixelRatio;
    262 
    263         /**
    264          * List of `CanvasEntry` instances.
    265          *
    266          * @type {Array}
    267          */
    268         this.canvases = [];
    269 
    270         /**
    271          * @type {HTMLElement}
    272          */
    273         this.progressWave = null;
    274 
    275         /**
    276          * Class used to generate entries.
    277          *
    278          * @type {function}
    279          */
    280         this.EntryClass = CanvasEntry;
    281 
    282         /**
    283          * Canvas 2d context attributes.
    284          *
    285          * @type {object}
    286          */
    287         this.canvasContextAttributes = params.drawingContextAttributes;
    288 
    289         /**
    290          * Overlap added between entries to prevent vertical white stripes
    291          * between `canvas` elements.
    292          *
    293          * @type {number}
    294          */
    295         this.overlap = 2 * Math.ceil(params.pixelRatio / 2);
    296 
    297         /**
    298          * The radius of the wave bars. Makes bars rounded
    299          *
    300          * @type {number}
    301          */
    302         this.barRadius = params.barRadius || 0;
    303 
    304 
    305             if (params.colorMap) {
    306                 if (params.colorMap.length < 256) {
    307                     throw new Error('Colormap must contain 256 elements');
     237   
     238        if (params.colorMap) {
     239            if (params.colorMap.length < 256) {
     240                throw new Error('Colormap must contain 256 elements');
     241            }
     242            for (let i = 0; i < params.colorMap.length; i++) {
     243                const cmEntry = params.colorMap[i];
     244                if ((cmEntry.length !== 4) && (cmEntry.length !== 3)) {
     245                    throw new Error(
     246                        'ColorMap entries must contain 3 (rgb) or 4 (rgba) values'
     247                    );
    308248                }
    309                 for (let i = 0; i < params.colorMap.length; i++) {
    310                     const cmEntry = params.colorMap[i];
    311                     if ((cmEntry.length !== 4) && (cmEntry.length !== 3)) {
    312                         throw new Error(
    313                             'ColorMap entries must contain 3 (rgb) or 4 (rgba) values'
    314                         );
    315                     }
    316                 }
    317                 this.colorMap = params.colorMap;
    318             } else {
    319                 this.colorMap = [];
    320                 for (let i = 0; i < 256; i++) {
    321                     const val = (255 - i) / 256;
    322                     this.colorMap.push([val, val, val, 1]);
    323                 }
    324             }
    325    
     249            }
     250            this.colorMap = params.colorMap;
     251        } else {
     252            this.colorMap = [];
     253            for (let i = 0; i < 256; i++) {
     254                const val = (255 - i) / 256;
     255                this.colorMap.push([val, val, val, 1]);
     256            }
     257        }   
    326258    }
    327259
     
    329261     * Initialize the drawer
    330262     */
     263    /*
    331264    init() {
    332265        this.createWrapper();
    333266        this.createElements();
    334267    }
    335 
     268    */
     269   
    336270    /**
    337271     * Create the canvas elements and style them
    338272     *
    339273     */
     274    /*
    340275    createElements() {
    341276        this.progressWave = this.wrapper.appendChild(
     
    357292        this.addCanvas();
    358293        this.updateCursor();
    359     }
     294    }*/
    360295
    361296    /**
    362297     * Update cursor style
    363298     */
     299   
    364300    updateCursor() {
    365301        this.style(this.progressWave, {
    366             borderRightWidth: this.params.cursorWidth + 'px',
    367             borderRightColor: this.params.cursorColor
     302            //borderRightWidth: this.params.cursorSpectrumWidth + 'px',
     303            //borderRightColor: this.params.cursorSpectrumColor
     304            borderRightWidth: '4px',
     305            borderRightColor: 'rgba(255,255,255,0.3)'
    368306        });
    369307    }
    370 
     308   
     309   
    371310    /**
    372311     * Adjust to the updated size by adding or removing canvases
    373312     */
     313    /*
    374314    updateSize() {
    375315        const totalWidth = Math.round(this.width / this.params.pixelRatio);
     
    399339        });
    400340    }
    401 
     341    */
     342   
    402343    /**
    403344     * Add a canvas to the canvas list
    404345     *
    405346     */
     347    /*
    406348    addCanvas() {
    407349        const entry = new this.EntryClass();
     
    443385        this.canvases.push(entry);
    444386    }
    445 
     387    */
     388   
    446389    /**
    447390     * Pop single canvas from the list
    448391     *
    449392     */
     393    /*
    450394    removeCanvas() {
    451395        let lastEntry = this.canvases[this.canvases.length - 1];
     
    467411        this.canvases.pop();
    468412    }
    469 
     413    */
     414   
    470415    /**
    471416     * Update the dimensions of a canvas element
     
    475420     * @param {number} height The new height of the element
    476421     */
     422    /*
    477423    updateDimensions(entry, width, height) {
    478424        const elementWidth = Math.round(width / this.params.pixelRatio);
     
    485431        this.style(this.progressWave, { display: 'block' });
    486432    }
    487 
     433    */
     434   
    488435    /**
    489436     * Clear the whole multi-canvas
    490437     */
     438    /*
    491439    clearWave() {
    492440        util.frame(() => {
     
    494442        })();
    495443    }
    496 
     444*/
    497445
    498446    drawPeaks(peaks, length, start, end) {
     
    504452    }
    505453
    506         resample(oldMatrix) {
     454    resample(oldMatrix) {
    507455        const columnsNumber = this.width;
    508456        const newMatrix = [];
     
    680628     * @returns {void}
    681629     */
     630   
    682631    drawBars(peaks, channelIndex, start, end) {
    683632        return this.prepareDraw(
     
    745694     * @returns {void}
    746695     */
     696    /*
    747697    drawWave(peaks, channelIndex, start, end) {
    748698        return this.prepareDraw(
     
    780730        );
    781731    }
    782 
     732    */
     733   
    783734    /**
    784735     * Tell the canvas entries to render their portion of the waveform
     
    794745     * @param {channelIndex} channelIndex The channel index of the line drawn
    795746     */
     747    /*
    796748    drawLine(peaks, absmax, halfH, offsetY, start, end, channelIndex) {
    797749        const { waveColor, progressColor } = this.params.splitChannelsOptions.channelColors[channelIndex] || {};
     
    801753        });
    802754    }
    803 
     755    */
     756   
    804757    /**
    805758     * Draw a rectangle on the multi-canvas
     
    811764     * @param {number} radius Radius of the rectangle
    812765     */
     766    /*
    813767    fillRect(x, y, width, height, radius) {
    814768        const startCanvas = Math.floor(x / this.maxCanvasWidth);
     
    845799        }
    846800    }
    847 
     801    */
     802   
    848803    /**
    849804     * Returns whether to hide the channel from being drawn based on params.
     
    852807     * @returns {bool} True to hide the channel, false to draw.
    853808     */
     809    /*
    854810    hideChannel(channelIndex) {
    855811        return this.params.splitChannels && this.params.splitChannelsOptions.filterChannels.includes(channelIndex);
    856812    }
    857 
     813    */
     814   
    858815    /**
    859816     * Performs preparation tasks and calculations which are shared by `drawBars`
     
    872829     * @returns {void}
    873830     */
     831    /*
    874832    prepareDraw(peaks, channelIndex, start, end, fn, drawIndex) {
    875833        return util.frame(() => {
     
    928886        })();
    929887    }
    930 
     888    */
     889   
    931890    /**
    932891     * Set the fill styles for a certain entry (wave and progress)
     
    936895     * @param {string} progressColor Progress color to draw this entry
    937896     */
     897    /*
    938898    setFillStyles(entry, waveColor = this.params.waveColor, progressColor = this.params.progressColor) {
    939899        entry.setFillStyles(waveColor, progressColor);
    940900    }
    941 
     901*/
    942902    /**
    943903     * Return image data of the multi-canvas
     
    954914     * canvas.
    955915     */
     916    /*
    956917    getImage(format, quality, type) {
    957918        if (type === 'blob') {
     
    968929        }
    969930    }
    970 
     931    */
     932   
    971933    /**
    972934     * Render the new progress
     
    974936     * @param {number} position X-offset of progress position in pixels
    975937     */
     938    /*
    976939    updateProgress(position) {
    977940        this.style(this.progressWave, { width: position + 'px' });
    978941    }
     942*/
    979943}
Note: See TracChangeset for help on using the changeset viewer.