instrument.js 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. this.clickEventMethod = function() {
  2. this.synth.triggerAttackRelease(['C4'], ['8n'], 0.3);
  3. }
  4. this.doButtonTriggerdownAction = function(buttonID){
  5. let transportNode = this.find('//' + 'globalTransport')[0];
  6. if(this.playButton.displayName == "playButton"){
  7. //this.transportLine.playing
  8. this.globalBeat = this.globalBeat? false : true;
  9. if(this.globalBeat){
  10. this.playButton.baseColor = 'red';
  11. this.playButton.textNode.value = 'Stop'
  12. if(!transportNode.playing)
  13. transportNode.play()
  14. } else {
  15. this.playButton.baseColor = 'green';
  16. this.playButton.textNode.value = 'Play'
  17. }
  18. }
  19. }
  20. this.initialize = function(){
  21. this.playButton.init();
  22. }
  23. this.onGlobalBeat = function (obj) {
  24. //dispatch the beat example send OSC
  25. let transportNode = this.find('//' + obj.name)[0];
  26. let rate = transportNode.animationRate; // 1 by default
  27. let tps = transportNode.animationTPS; // 30 by default
  28. //this.transportLine.translateTo([obj.beat*0.2, 0, 0]);
  29. let end = this.transportLine.end;
  30. if(obj.beat == 0)
  31. this.transportLine.translateTo([end, 0, 0], rate - 0.1);
  32. if(obj.beat == tps - 1)
  33. this.transportLine.translateTo([0, 0, 0]);
  34. }