Ignore:
Timestamp:
2023-02-02T17:34:42+13:00 (16 months ago)
Author:
davidb
Message:

isRecordingUserAV has basic state/workflow. Draws directly onto a canvas; currently not saved in local storage

File:
1 edited

Legend:

Unmodified
Added
Removed
  • gs3-installations/mars/trunk/sites/mars/collect/amc-essentia/js/av_document.js

    r37238 r37254  
    1818function AVPlay()
    1919{
     20    // Restore play/pause toggle button back to 'ready to play' i.e., showing pause button
    2021    $('#ws-play-icon' ).hide();
    2122    $('#ws-pause-icon').show();
     
    387388    });
    388389
     390    wavesurfer.on('finish', function () {
     391    // auto stop RecordingUserAV
     392    av_chart_record_finish();
     393    });
     394   
    389395    wavesurfer.on('ready', function () {
    390396
     
    532538}
    533539
     540var isRecordingUserAV = false;
     541
     542function crsc_popup_close($elem)
     543{
     544    $elem.parents('.dialog-ovelay').fadeOut(500, function () {
     545    $elem.remove();
     546    });
     547}
     548
     549function crsc_popup_cancel_callback()
     550{
     551    console.log("Canceling RecordingUserAV");
     552
     553    var av_canvas = document.getElementById("av-chart-canvas-unlabeled");
     554    var av_context = av_canvas.getContext("2d");
     555
     556    av_context.clearRect(0, 0, av_canvas.width, av_canvas.height);
     557   
     558    crsc_popup_close($(this));
     559
     560   
     561    if ('p_frameOffset' in gs.cgiParams) {
     562    var frameOffset = gs.cgiParams['p_frameOffset'];
     563    wavesurfer.seekTo(frameOffset/AMC_SONG_DURATION);
     564    recommendFromPos();
     565    displayClampedCurrentTimeAndAV();
     566    }
     567    else {
     568    AVSeekTo(0);
     569    }
     570   
     571}
     572
     573function crsc_popup_resume_callback()
     574{
     575    console.log("Resuming RecordingUserAV");
     576    isRecordingUserAV = true;
     577    crsc_popup_close($(this));
     578    AVPlay();
     579}
     580
     581function crsc_popup_save_callback()
     582{
     583    console.log("Saving to your browser RecordingUserAV");
     584    crsc_popup_close($(this));
     585}
     586
     587
    534588
    535589function av_chart_record_click(elem,event)
    536590{
    537     console.error("Recording mode to be implemented!")
     591    if (isRecordingUserAV == false) {
     592    isRecordingUserAV = true;
     593
     594    if (!wavesurfer.backend.isPaused()) {
     595        console.log("Starting recording user's AV values");
     596        AVSeekTo(0);
     597    }
     598    else {
     599        console.log("Resuming recording user's AV values");
     600    }
     601    AVPlay()
     602    }
     603    else {
     604    AVEnsurePaused();
     605    // Have stopped recording
     606    // => Store recorded values into LocalStorage
     607    isRecordingUserAV = false;
     608
     609
     610    CancelResumeSaveConfirm('Customised AV Recording', 'Would you like to save this AV Recording?',
     611                'Cancel and Start Over',                   'Resume Recording',         "Save",
     612                crsc_popup_cancel_callback, crsc_popup_resume_callback, crsc_popup_save_callback
     613                   );
     614   
     615    }
     616}
     617
     618function av_chart_record_finish(elem,event)
     619{
     620    // Restore play/pause toggle button back to 'ready to play'
    538621    AVSeekTo(0);
    539     AVPlayPause();
    540     if (wavesurfer.backend.isPaused()) {
    541     alert("Sorry, capturing and saving of AV values not currently implemented!");
    542     }
    543 }
    544 
     622    $('#ws-play-icon' ).show();
     623    $('#ws-pause-icon').hide();
     624    $('#ws-playpause-label').html("Play");
     625
     626    if (isRecordingUserAV == true) {
     627    isRecordingUserAV = false;
     628
     629    CancelResumeSaveConfirm('Customised  AV Recording', 'Would you like to save this AV Recording?',
     630                'Cancel and Start Over',                   null, "Save",
     631                crsc_popup_cancel_callback, null, crsc_popup_save_callback
     632                   );
     633    }
     634
     635   
     636}
     637
     638   
    545639function initPlayerVisual() {
    546640
     
    581675   
    582676    $('#av-chart-img-unlabeled').hide();
     677    $('#av-chart-canvas-unlabeled').hide();
    583678    $('#av-chart-img').show();
     679    $('#av-chart-canvas').show();
    584680
    585681    $('#start-av-recommendation').show();
     
    603699        // Reset what is being display to the default (the av-chart, not the record one)
    604700        $('#av-chart-img-unlabeled').hide();
     701        $('#av-chart-chart-unlabeled').hide();
    605702        $('#av-chart-img').show();
     703        $('#av-chart-canvas').show();
    606704
    607705        $('#start-av-recommendation').show();
     
    687785        // Ensure it is the RecordAV chart that is shown
    688786        $('#av-chart-img').hide();
     787        $('#av-chart-canvas').hide();
    689788        $('#av-chart-img-unlabeled').show();
     789        $('#av-chart-canvas-unlabeled').show();
    690790
    691791        $('#start-av-recommendation').hide();
     
    707807function mouse_xy_to_av(elem,event,circ_x_org,circ_y_org,circ_radius)
    708808{
    709     //var circ_x_org = 183;
    710     //var circ_y_org = 194;
    711     //var circ_radius = 130;
    712    
    713809    var relX = event.pageX - $(elem).offset().left;
    714810    var relY = event.pageY - $(elem).offset().top;
     
    722818}
    723819
    724    
     820
     821// Need to be very careful with order of valenceVal and arousalVal
     822// Here they are ordered to match x,y
     823
     824function av_to_canvas_xy(valenceVal, arousalVal, circ_x_org,circ_y_org,circ_radius)
     825{
     826    //var canvasX = (valenceVal * circ_radius) - circ_x_org; // effectively "times -1"
     827    var canvasX = circ_x_org - (valenceVal * circ_radius);
     828    var canvasY = circ_y_org - (arousalVal * circ_radius);
     829   
     830
     831    return { 'canvasX': canvasX, 'canvasY': canvasY };
     832}
     833
     834
    725835$(document).ready(function() {
    726836
    727     console.log(`loggedInUsername = '${gs.variables.loggedInUsername}'`);
     837    console.log("AV Recording now always possible, without logging in (pseudo username: mars)");
     838    gs.variables.loggedInUsername = "mars";
     839    //console.log(`loggedInUsername = '${gs.variables.loggedInUsername}'`);
    728840    if (gs.variables.loggedInUsername != "") {
     841    // Logged in
    729842    $('#login-to-record-av').hide();
    730843    $('#record-av').show();
     
    760873    var circ_x_org = 137;
    761874    var circ_y_org = 145;
    762     //var circ_radius = 234 - 137;
    763875    var circ_radius = 97;
    764876   
    765     //var relX = event.pageX - $(this).offset().left;
    766         //var relY = event.pageY - $(this).offset().top;
    767 
    768     //var recValenceVal = -1 * (circ_x_org - relX) / circ_radius;
    769     //var recArousalVal = +1 * (circ_y_org - relY) / circ_radius;
    770 
    771 
    772     //var avRadius = Math.sqrt(recValenceVal*recValenceVal + recArousalVal*recArousalVal);
    773 
    774877    var av_rec = mouse_xy_to_av(this,event,circ_x_org,circ_y_org,circ_radius);
    775878
     
    806909    $('#av-chart-img-unlabeled').on("click",function(event) {
    807910    av_chart_record_click(this,event);
    808     //console.error("Recording mode to be implemented!")
    809     //AVSeekTo(0);
    810     //AVPlayPause();
    811     //if (wavesurfer.backend.isPaused()) {
    812     //    alert("Sorry, capturing and saving of AV values not currently implemented!");
    813     //}
    814911    });
    815912
     
    823920    var circ_radius = 130;
    824921   
    825     //var relX = event.pageX - $(this).offset().left;
    826         //var relY = event.pageY - $(this).offset().top;
    827 
    828     //var recValenceVal = -1 * (circ_x_org - relX) / circ_radius;
    829     //var recArousalVal = +1 * (circ_y_org - relY) / circ_radius;
    830 
    831 
    832     //var avRadius = Math.sqrt(recValenceVal*recValenceVal + recArousalVal*recArousalVal);
    833 
    834922    var av_rec = mouse_xy_to_av(this,event,circ_x_org,circ_y_org,circ_radius);
    835923
     
    847935            $("#av-recording-coords").text(relBoxCoords);
    848936    }
     937
     938    if ((recAVInside) && (isRecordingUserAV)) {
     939        //var xy_rec = av_to_canvas_xy(recValenceVal,recArousalVal, circ_x_org,circ_y_org, circ_radius);
     940        //var canvas_x = xy_rec.canvasX;
     941        //var canvas_y = xy_rec.canvasY;
     942
     943        var canvas_x = event.pageX - $(this).offset().left;
     944        var canvas_y = event.pageY - $(this).offset().top;
     945
     946        console.log("canvas x,y = " + canvas_x + " , " + canvas_y);
     947       
     948        var av_canvas = document.getElementById("av-chart-canvas-unlabeled");
     949        var av_context = av_canvas.getContext("2d");
     950
     951        av_context.fillStyle = "rgba(190,0,0,0.1)";
     952        //av_context.fillStyle = "rgba(130,0,0,0.1)";
     953        //av_context.fillStyle = "rgba(78,196,108,0.1)";
     954        av_context.beginPath();
     955        av_context.arc(canvas_x, canvas_y, 5, 0, 2 * Math.PI);
     956        av_context.fill();
     957    }
    849958   
    850959    if (recAVInside != prevRecAVInside) {
    851960        if (recAVInside) {
    852961        // crosshairs on
    853         //$('#av-chart-img-unlabeled').css("cursor","crosshair");
    854         var crosshair_record_url = gs.variables.collImagesURL + "/font_awesome--crosshair-red32.png";
    855         //console.log("crosshair_record_url = " + crosshair_record_url);
    856         //console.log("url('"+crosshair_record_url+"') 16 16, crosshair");
    857        
     962        var crosshair_record_url = gs.variables.collImagesURL + "/crosshair-cursor-red32.png";
    858963        $('#av-chart-img-unlabeled').css("cursor","url('"+crosshair_record_url+"') 16 16, crosshair");
    859964        }
Note: See TracChangeset for help on using the changeset viewer.