Ignore:
Timestamp:
2022-10-24T08:34:28+13:00 (19 months ago)
Author:
davidb
Message:

Changes after work on macrocarpa in the DL lab, testing with Safari

File:
1 edited

Legend:

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

    r36862 r36865  
     1var AMC_SONG_DURATION = 30;
     2
     3var currentPosIsZero = true;
     4var currentPosRunup  = 0;
     5
     6
     7function AVEnsurePaused()
     8{
     9    if (!wavesurfer.backend.isPaused()) {   
     10    $('#ws-pause-icon').hide();
     11    $('#ws-play-icon' ).show();
     12    $('#ws-playpause-label').html("Play");
     13    }
     14   
     15    wavesurfer.pause();
     16}
     17
     18function AVPlay()
     19{
     20    $('#ws-play-icon' ).hide();
     21    $('#ws-pause-icon').show();
     22    $('#ws-playpause-label').html("Pause");
     23
     24    if (currentPosRunup>0) {
     25    var skip_amount = -1 * currentPosRunup;
     26    wavesurfer.skip(skip_amount);
     27    currentPosRunup = 0;   
     28    }
     29   
     30    wavesurfer.play();
     31   
     32}
     33
    134function AVPlayPause()
    235{
    3     return wavesurfer.backend.isPaused() ? wavesurfer.play() : wavesurfer.pause();
     36    if (wavesurfer.backend.isPaused()) {
     37    AVPlay();
     38    }
     39    else {
     40    AVEnsurePaused();
     41    }
     42   
     43    //return wavesurfer.backend.isPaused() ? wavesurfer.play() : wavesurfer.pause();
    444}
    545
     
    3676    // clamp to ensure >= 6.0 secs
    3777    var current_time = Math.max(6.0,wavesurfer.getCurrentTime());
    38    
    39     wavesurfer.pause();
     78    var current_time_1dp = current_time.toFixed(1);
     79    AVEnsurePaused();
    4080   
    4181    weka_segment = Math.round(current_time/3) * 3;
     
    4787    form.elements["s1.arousal"].value = arousal_val;
    4888    form.elements["s1.valence"].value = valence_val;
     89
     90    $('#makeRecommendationFrom-AV').html(`(@${current_time_1dp} secs: arousal=${arousal_val}, valence=${valence_val})`);
    4991   
    5092
     
    83125    };
    84126
    85 
     127/*
    86128    var argsFixed = {
    87129    "a": "q",
     
    101143    "excerptid" : "resultsArea"
    102144    };
     145*/
    103146   
    104147    var url = "https://mars.so-we-must-think.space/greenstone3/library";
     148
     149    $('#recommendationArea').css("cursor","wait");
     150    $('#resultsAreaDiv').html("Retrieving recommendation ...");
    105151   
    106152    $.ajax({
     
    109155    data: args
    110156    })
    111     .done(function( msg ) {
    112         $('#resultsAreaDiv').html(msg);
    113     //alert( "Data Saved: " + msg );
    114     });
    115 
     157    .always(function() {
     158        $('#recommendationArea').css("cursor","revert");
     159    })
     160    .fail(function(jqXHR,textStatus) {
     161        console.error( "Request failed: " + textStatus);
     162    })
     163    .done(function(html_result) {
     164        $('#resultsAreaDiv').html(html_result);
     165
     166        const updated_url = new URL(window.location);
     167        updated_url.searchParams.set('p.frameOffset', current_time);
     168        //window.history.pushState({}, '', url + "?p.frameOffset=" + current_time);
     169        //window.history.pushState({}, '', updated_url);
     170        window.history.replaceState({}, '', updated_url);
     171
     172       
     173    });
     174   
    116175    // stop submit
    117176    return false;
    118177
     178    // force GET method request to go ahead
    119179    //return true;
    120180}
    121181
    122182
    123 var currentPosIsZero = true;
    124183
    125184function recommendFromStart()
     
    140199function postInitWavesurfer(wavesurfer)
    141200{
     201    console.log("postInitWavesurfer called with wavesufer = " + wavesurfer);
     202   
    142203    wavesurfer.load(gs.variables.mp3url);
    143204   
     
    157218
    158219    wavesurfer.on('ready', function () {
     220
     221    console.log("**** wavesurfer ready()");
    159222   
    160223    if ('p_frameOffset' in gs.cgiParams) {
     
    162225        //console.log("**** starting play @ " + frameOffset);
    163226        //wavesurfer.play(frameOffset);
    164         wavesurfer.seekTo(frameOffset/30.0);
     227        //console.log("**** setting play seek @ " + frameOffset);
     228        wavesurfer.seekTo(frameOffset/AMC_SONG_DURATION);
     229
     230        if (frameOffset>1.0) {
     231        currentPosRunup = 1.0; // 1 second
     232        }
    165233    }
    166234    });
    167235
    168236}
     237
     238$(document).ready(function() {
     239
     240    const doc_url = new URL(window.location);
     241    var renderWave = doc_url.searchParams.get('renderWave');
     242
     243    if (renderWave && (renderWave == 1)) {
     244    // showing the waveform => offer link to spectrogram
     245    const sts_url = new URL(window.location);
     246    sts_url.searchParams.set('renderWave', 0);
     247    $('#switch-to-spectrogram').attr("href",sts_url);
     248    $('#switch-to-waveform').hide();
     249    }
     250    else {
     251    // show the spectrogram => offer link to waveform
     252   
     253    const stw_url = new URL(window.location);
     254    stw_url.searchParams.set('renderWave', 1);
     255    $('#switch-to-waveform').attr("href",stw_url);
     256    $('#switch-to-spectrogram').hide();
     257    }
     258   
     259});
     260         
Note: See TracChangeset for help on using the changeset viewer.