Changeset 37254 for gs3-installations


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

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

Location:
gs3-installations/mars/trunk/sites/mars/collect/amc-essentia
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • gs3-installations/mars/trunk/sites/mars/collect/amc-essentia/etc/collectionConfig.xml

    r37238 r37254  
    620620                  <span id="hide-av-chart" class="display-view-modes hd-chart-label" onclick="return hideAVChart();">Hide AV Chart</span>
    621621                  </span>
     622                  <!-- Keep if ever wanting to go back to logging in to record AV experience -->
     623                  <!--
    622624                  <span style="display: inline-block; width: 270px;">
    623625                | <span id="login-to-record-av" class="display-view-modes" onclick="loginToRecord()">&#x23fa; Login to record <i>your</i> AV experience</span>
    624                 <span id="record-av"          class="display-view-modes" onclick="loginToRecord()">
    625                   &#x23fa; Record <i>your</i> AV experience (<a id="record-av-logout" href="">logout</a>)
     626                  <span id="record-av"          class="display-view-modes" onclick="loginToRecord()">
     627                    &#x23fa; Record <i>your</i> AV experience (<a id="record-av-logout" href="">logout</a>)
    626628                </span>
    627629                  </span>
     630                  -->
     631
     632                  <span style="display: inline-block; width: 270px;">
     633                | <span id="record-av"          class="display-view-modes" style="display: inline;" onclick="loginToRecord()">
     634                    &#x23fa; Customise your AV experience
     635                </span>
     636                  </span>
     637                 
    628638                </div>
    629639
     
    732742      <style>
    733743        .recommend-cursor {
    734         cursor: url(<xsl:value-of select="$library_name"/>/sites/<xsl:value-of select="$site_name"/>/collect/<xsl:value-of select="$collName"/>/images/font_awesome--crosshair-black32.png) 16 16, crosshair
     744        cursor: url(<xsl:value-of select="$library_name"/>/sites/<xsl:value-of select="$site_name"/>/collect/<xsl:value-of select="$collName"/>/images/crosshair-cursor-black32.png) 16 16, crosshair
    735745        }
    736746        .record-cursor {
    737           cursor: url(<xsl:value-of select="$library_name"/>/sites/<xsl:value-of select="$site_name"/>/collect/<xsl:value-of select="$collName"/>/images/font_awesome--crosshair-red32.png) 16 16, crosshair
     747          cursor: url(<xsl:value-of select="$library_name"/>/sites/<xsl:value-of select="$site_name"/>/collect/<xsl:value-of select="$collName"/>/images/crosshair-cursor-red32.png) 16 16, crosshair
    738748        }
    739749      </style>
    740750      <gsf:variable name="collImagesURL"><xsl:value-of select="$library_name"/>/sites/<xsl:value-of select="$site_name"/>/collect/<xsl:value-of select="$collName"/>/images</gsf:variable> 
    741751      <div id="start-av-recording" style="display:none;">
    742         To make an AV-Recording: <span id="av-recording-coords" style="display:none;">AV coord: </span>
     752        To customise your Musical Affect Recommender experience, use the AV circle below to record
     753        the Arousal-Valence levels you perceive.  This is used by MARS to personalise the
     754        recommendations the system makes.  The more musical works you record AV values for,
     755        the more data MARS has to go on.
     756        <span id="av-recording-coords" style="display:none;">AV coord: </span>
    743757        <ul>
    744758          <li>Click in the centre of the Arousal-Valence space below to initiate recording</li>
    745759          <li>Move your mouse-cursor around inside the circle to reflect the Arousal-Valence levels you perceive</li>
    746           <li>Click again inside the circle at any point, if you want to cancel the recording</li>
     760          <li>Click again inside the circle at any point, if you want to cancel/pause or save the recording</li>
     761          <li>If you listen all the way through to the end of the work, you will be promted at the end about canceling or saving the recording.</li>
    747762        </ul>
    748763      </div>
    749764   
     765      <gsf:div id="cancel-resume-save-confirm-div"/>
    750766     
    751       <div id="av-chart-div" style="position: relative; heightXXX: 325px; width: 300px; margin: auto">            <!-- av-chart-width av-chart-height + 25-->
    752         <div style="position: absolute; top: 0; left: 0; width: 300px; height: 300px; pointer-events: none;">  <!-- av-chart-width -->
     767      <div id="av-chart-div" style="position: relative; heightXXX: 325px; width: 300px; widthXXXYYY: 400px; margin: auto">            <!-- av-chart-width av-chart-height + 25-->
     768        <div style="position: absolute; top: 0; leftXXXYYY: 50px; width: 300px; height: 300px; pointer-events: none;">  <!-- av-chart-width -->
    753769          <canvas id="av-chart-canvas" style="XXwidth: 100%; height: 300px;">                                  <!-- av-chart-width -->
    754770        Your browser does not support the canvas element
     
    756772        </div>
    757773        <!--                           VVV av-chart-width -->
    758         <img id="av-chart-img" classXXXX="recommend-cursor" width="300"                                                                     
    759          style="cursor: crosshair;"
     774        <img id="av-chart-img" width="300"
     775         style="cursor: crosshair; padding-leftXXXYYY: 50px;"
    760776         src="{$library_name}/sites/{$site_name}/collect/{$collName}/images/av-diagram-bw.svg" /> 
    761        
    762         <img id="av-chart-img-unlabeled" class="record-cursor" width="400"
    763          style="cursorXX: crosshair; background-colorXX: #fefefe; display: none;"
    764          src="{$library_name}/sites/{$site_name}/collect/{$collName}/images/av-diagram-bw--unlabeled.svg" /> 
    765 
     777
     778        <div>
     779          <canvas id="av-chart-canvas-unlabeled" width="400" height="362"
     780              style="position: absolute; top: 0; left: 0px; widthXXX: 400px; heightXXX: 362px; heightXXX: 100%; opacity:1.0; pointer-events: none;">
     781        Your browser does not support the canvas element
     782          </canvas>
     783          <img id="av-chart-img-unlabeled" class="record-cursor" width="400"
     784         style="background-colorXX: #fefefe; display: none;"
     785         src="{$library_name}/sites/{$site_name}/collect/{$collName}/images/av-diagram-bw--unlabeled.svg" />
     786        </div>
    766787       
    767788        <!--
  • 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.