Ignore:
Timestamp:
2015-08-04T13:50:35+12:00 (9 years ago)
Author:
davidb
Message:

Development work done in at JCDL

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/model-sites-dev/respooled/collect/popup-video-respooled/js/jquery-drums.js

    r29938 r30093  
    11// Based on:
    22//   http://www.theonlytutorials.com/jquery-drum-sets-html5-audio-tag-example/
     3
     4
     5var hitDrumStartCurrentTime = null;
     6var hitDrumEndCurrentTime;
     7var hitDrumMidiPitch;
     8var hitDrumMidiPitchReadable;
     9
     10function calcDrumMidiNoteInfo() {
     11    if (hitDrumStartCurrentTime != null) {
     12
     13    var hitDrumDuration = hitDrumEndCurrentTime - hitDrumStartCurrentTime;
     14   
     15    // console.log("**** " + playedNotePitch + " (midi pitch = " + playedMidiPitch+ ") startTime = ", relativePlayStartTime + ", duration = " + playedDuration);
     16
     17    if (mediaPlayedNotes[String(mediaStartPlayTime)]) {
     18       
     19        mediaPlayedNotes[String(mediaStartPlayTime)].push(
     20        { 'type'         : "drum",
     21          'midiPitch'    : hitDrumMidiPitch,
     22          //'midiNoteOn'   : relativePlayedNoteStartTime,
     23          //'midiNoteOff'  : relativePlayedNoteEndTime,
     24          'startCurrentTime' : hitDrumStartCurrentTime,
     25          'duration'     : hitDrumDuration,
     26          'startPercTime': hitDrumStartCurrentTime/mediaPlayer.duration,
     27          'humanReadble' : hitDrumMidiPitchReadable }
     28        );
     29    }
     30   
     31    }
     32}
    333
    434$(document).ready(function() {
     
    2656   
    2757    $('.drum').mousedown(function() {
     58
     59    hitDrumStartCurrentTime = mediaPlayer.currentTime;
     60    hitDrumMidiPitchReadable = $(this).attr('id');
     61    hitDrumMidiPitch = hitDrumMidiPitchReadable.replace(/^drum/,"");
    2862   
    2963    //find the drum hit and play the respective audio
     
    3165    drum = eval(drum);
    3266   
    33     if (drum.ended) {
     67    if (drum.ended) {       
    3468        $(this).addClass('hit');
    3569        drum.play();
     
    4074        console.log("Error thrown when playing drum sound: " + e);
    4175        }
     76
     77        // Force finish of previous drum hit
     78        hitDrumEndCurrentTime = mediaPlayer.currentTime;
     79        calcDrumMidiNoteInfo();
     80        hitDrumStartCurrentTime = mediaPlayer.currentTime;
     81        hitDrumEndCurrentTime = null;
     82
    4283        $(this).addClass('hit');
    4384            drum.play();
     
    4687
    4788    $('.drum').mouseup(function() {
     89    hitDrumEndCurrentTime = mediaPlayer.currentTime;
     90    calcDrumMidiNoteInfo();
     91    hitDrumStartCurrentTime = null;
     92   
    4893    $(this).removeClass('hit');
    4994    });
Note: See TracChangeset for help on using the changeset viewer.