Changeset 29942 for main/trunk/model-sites-dev/respooled/collect/popup-video-respooled/js/jam-guitar.js
- Timestamp:
- 2015-06-01T09:59:31+12:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/model-sites-dev/respooled/collect/popup-video-respooled/js/jam-guitar.js
r29878 r29942 1 "use strict"; 2 1 3 // Script derived from Chrome Jam 2 4 … … 236 238 this._strumForce = 5; 237 239 this._strumDuration = 100; 238 MIDI.noteOn(0, this._midiPitch, 40); 239 console.log("*** Setting Jam guitar strumForce = 5"); 240 240 if (this._midiPitch>=0) { 241 MIDI.noteOn(0, this._midiPitch, 40); 242 console.log("*** Setting Jam guitar strumForce = 5"); 243 } 241 244 }; 242 245 … … 260 263 else if (this._strumDuration == 0) { 261 264 this._strumDuration = -1; 262 console.log("*** setting strumDuration = 0"); 263 MIDI.noteOff(0, this._midiPitch, 0); 265 if (this._midiPitch>=0) { 266 console.log("*** setting strumDuration = 0"); 267 MIDI.noteOff(0, this._midiPitch, 0); 268 } 264 269 } 265 270 }; … … 283 288 284 289 //var jamMidiStringPitches = [ 60, 64, 67, 72, 76, 79 ]; 285 var jamMidiStringPitches = [ 48, 52, 55, 60, 64, 67 ]; 290 //var jamMidiStringPitches = [ 48, 52, 55, 60, 64, 67 ]; 291 // E A D G B E 292 // 52, 57, 62, 67, 71, 76 293 var jamMidiStringPitches = [ 52, 57, 62, 67, 71, 76 ]; 286 294 287 295 StringInstrument.prototype.create = function() { … … 295 303 }; 296 304 305 StringInstrument.prototype.setStringFret = function(spos,fbase, fpos) { 306 307 var s = this.strings[spos]; 308 if (fpos>=0) { 309 s._midiPitch = jamMidiStringPitches[spos] + fbase + fpos; 310 } 311 else { 312 s._midiPitch = -1; 313 } 314 315 }; 316 317 318 297 319 var lastTime = 0; 298 320 … … 318 340 }; 319 341 342 var guitar = null; 320 343 $(document).ready(function() { 321 var guitar = new StringInstrument("jamStage", "jamStrings", 6); 344 console.log("**** creating guitar"); 345 guitar = new StringInstrument("jamStage", "jamStrings", 6); 322 346 }); 347 348 var jamLineupLen = 17; 349 350 var jam_chords = { 'maj': [ 'C', 'C#' ,'Db', 'D', 'D#', 'Eb', 'E', 'F', 'F#', 'Gb', 'G', 'G#', 'Ab',' A', 'A#', 'Bb', 'B'], 351 'min': [ 'Cm','C#m','Dbm','Dm','D#m','Ebm','Em','Fm','F#m','Gbm','Gm','G#m','Abm','Am','A#m','Bbm','Bm'], 352 'cus': [ 'Dsus4' ], 353 'cus-skip': {"1":true,"4":true,"8":true,"11":true,"14":true} 354 }; 355 356 var cgc_mode = null; // cgc => 'current guitar chord' 357 var cgc_id = null; 358 359 360 function whitespaceTidyUp(str) 361 { 362 if (str) { 363 str = str.replace(/^\s+/,"").replace(/\s+$/,""); 364 } 365 366 return str; 367 } 368 369 370 function chordChange(bid) { 371 372 console.log("chordChange(" +bid + ")"); 373 if (cgc_id != null) { 374 $('#offscreen-jtab-chord-'+cgc_id).css("background-color","#FFFFFF"); 375 } 376 cgc_id = bid; 377 $('#offscreen-jtab-chord-'+cgc_id).css("background-color","rgba(46,82,164,0.50)"); 378 379 var cgc_code = whitespaceTidyUp($('#offscreen-jtab-chord-'+cgc_id+'>div>svg>text>tspan').html()); 380 console.log("*** clicked on guitar chord = " + cgc_code); 381 382 var cgc_data = jtab.Chords[cgc_code][0]; 383 var cgc_base_fret = cgc_data[0]; 384 //var cgc_string_frets = []; 385 for (var i=1; i<=6; i++) { 386 var cgc_string_fret_pos = cgc_data[i][0]; // pick out the fret position 387 //cgc_string_frets.push(cgc_string_fret_pos); // pick out the fret position 388 guitar.setStringFret(i-1,cgc_base_fret,cgc_string_fret_pos); 389 } 390 391 //console.log("*** strings = " + JSON.stringify(cgc_string_frets)); 392 } 393 394 395 396 function scaleJTab(pos) 397 { 398 399 // ... and scale the newly rendered element down 400 var $tab_svg = $('#offscreen-jtab-chord-'+pos+'>div>svg'); 401 $tab_svg.attr("width", "58"); // go thinner than 'natural' width of 69 (for a height of 59) 402 $tab_svg.attr("height","59"); 403 // True box is 0 0 138 118, but shaving off values so not so much white-space 404 $tab_svg[0].setAttribute("viewBox","20 0 90 118"); // W3C DOM way to avoid jquery lower-casing 'viewBox' into 'viewbox' 405 $tab_svg.parent().css("height","59px"); 406 407 } 408 409 function setChordLineupMode(mode) { 410 cgc_mode = mode; 411 412 if (mode == "cus") { 413 $('#addCustomChord').show({effect: "fade", duration: 400}); 414 } 415 else { 416 $('#addCustomChord').hide({effect: "fade", duration: 300}); 417 } 418 419 var lineup = jam_chords[mode]; 420 var lineup_len = lineup.length; 421 422 var lineup_skip = jam_chords[mode+"-skip"]; 423 424 425 for (var i=0; i<jamLineupLen; i++) { 426 427 var active_div_id = '#offscreen-jtab-chord-'+i; 428 429 if ((i<lineup_len) && 430 (!lineup_skip || (lineup_skip && !lineup_skip[""+i]))) { 431 console.log("*** lineup_skip = " + lineup_skip); 432 if (lineup_skip) { 433 console.log("*** lineup_skip lookup = " + lineup_skip[""+i]); 434 } 435 jtab.render($(active_div_id),lineup[i]); 436 437 scaleJTab(i); 438 } 439 else { 440 // make empty 441 jtab.render($(active_div_id).empty()); 442 } 443 444 } 445 446 if (cgc_id != null) { 447 chordChange(cgc_id); 448 } 449 } 450 451 452 453 function addCustomChord() { 454 455 456 var custom_lineup = jam_chords['cus']; 457 var custom_lineup_len = custom_lineup.length; 458 459 var custom_lineup_skip = jam_chords['cus-skip']; 460 461 462 var chord_text = whitespaceTidyUp($('#addCustomChordText').val()); 463 464 if (chord_text) { 465 // check the chord exists ... 466 if (jtab.Chords[chord_text]) { 467 // check there is space to add the chord ... 468 469 var custom_pos = null; 470 if (custom_lineup_len < jamLineupLen) { 471 // append (determin append pos) ... 472 473 custom_pos = custom_lineup_len; 474 475 // ... but need to increment one higher, if in a skip position 476 if (custom_lineup_skip["" + custom_pos]) { 477 custom_pos++; 478 } 479 480 custom_lineup[custom_pos] = chord_text; 481 482 } 483 else { 484 //replace the one that is currently highlighted 485 custom_pos = cgc_id; 486 custom_lineup[custom_pos] = chord_text; 487 } 488 489 jtab.render($('#offscreen-jtab-chord-'+custom_pos),chord_text); 490 scaleJTab(custom_pos); 491 492 // update local storage under this doc-id 493 } 494 495 496 } 497 498 499 }
Note:
See TracChangeset
for help on using the changeset viewer.