Skip to content

Commit

Permalink
Merge pull request #907 from DDMAL/issue827_OctaveSelection
Browse files Browse the repository at this point in the history
Added a button to the playback that toggles treble voice
  • Loading branch information
dchiller authored Sep 26, 2024
2 parents 090058c + 5ac27c4 commit bcb3800
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ function handleFlats (inputStr){

///////////////////////////////////////////////////////////////////////////////////
//Plays the volpiano notes using MIDI.js
function volpiano2midi(input_arr, note_dur) {
function volpiano2midi(input_arr, note_dur, treble_voice = false) {

//construct dictionary with pitch values
var pitch_dict = {};
Expand Down Expand Up @@ -127,6 +127,11 @@ function volpiano2midi(input_arr, note_dur) {
pitch_dict['t'] = 46; // make-shift Bb3
pitch_dict['u'] = 58; // make-shift Bb4
pitch_dict['v'] = 50; // make-shift Bb5
if (treble_voice) {
for (var key in pitch_dict) {
pitch_dict[key] += 12;
}
}

// create array of volpiano characters representing barlines
// for purposes of midi playback, these are treated as rests
Expand Down Expand Up @@ -252,21 +257,27 @@ export default Marionette.ItemView.extend({
ui : {
volpianoSyllables: ".volpiano-syllable",
btnPlay: ".btnPlay",
btnStop: ".btnStop"
btnStop: ".btnStop",
btnTreble: ".btnTreble"
},
events: {
"click .btnPlay": "submit",
"click .btnStop": "stop"
"click .btnStop": "stop",
"click .btnTreble": "toggleTreble"
},
submit: function mainPlay() {
var volArr = parse_volpiano(this.ui.volpianoSyllables);
this.ui.btnPlay.html("Playing...");
this.ui.btnPlay.attr("disabled", true);
volpiano2midi(volArr, .6);
volpiano2midi(volArr, .6, this.treble_voice);
},
stop: function(){
audioStopReset(MIDI);
},
toggleTreble: function(){
this.treble_voice = !this.treble_voice;
this.ui.btnTreble.html(this.treble_voice ? "Treble On" : "Treble Off");
},
stopChantAudio: function(){
if (MIDI.getContext().state === "running"){
audioStopReset(MIDI);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,5 @@ <h5>Full Text</h5>
<hr/>
<button class="btnPlay">Play Audio</button>
<button class="btnStop">Stop Audio</button>
<button class="btnTreble">Toggle Treble Voice</button>
<% } %>

0 comments on commit bcb3800

Please sign in to comment.