Skip to content

Commit

Permalink
theremin corrections
Browse files Browse the repository at this point in the history
  • Loading branch information
Imimimikimmmi committed Dec 7, 2023
1 parent 77b688f commit b101998
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
5 changes: 3 additions & 2 deletions assignments.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ <h1>Assignments for the Music & the Internet class:</h1>
<ul>
<li><a href="questionnaire.txt" target="_blank">Questionnaire</a></li>
<li><a href="fanpage/">Assignment 2: Fanpage </a></li>
<li><a href="musicbrainz/">Assignment 3: Musicbrainz API </a></li>
<li><a href="audio-compression/index.html">Assignment 4: Audio Compression </a></li>
<li><a href="/musicbrainz/">Assignment 3: Musicbrainz API </a></li>
<li><a href="/audio-compression/index.html">Assignment 4: Audio Compression </a></li>
<li><a href="/theremin/">Assignment 5: Virtual Theremin </a></li>
</ul>

</body>
Expand Down
11 changes: 7 additions & 4 deletions theremin/11.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,33 @@ const userGestureEvents = [
];

var userInteraction = false;
const unlockAudio = () => {
const unlockAudio = (e) => {
console.log("EVENT : "+e);
userGestureEvents.forEach(eventName => {
document.removeEventListener(eventName, unlockAudio);
userInteraction = true;
document.removeEventListener(eventName, unlockAudio);
});
};


// Turn theremin on
function thereminOn(oscillator) {
oscillator.play();
// console.log("USER INTERACTION : "+userInteraction);
if( userInteraction == false ) { window.alert("Please click on the page before playing so the browser can enable audio playback."); }
}

// Control the theremin
function thereminControl(e, oscillator, theremin) {
let x = e.offsetX;
let y = e.offsetY;
console.log(x, y);
// console.log(x, y);

let minFrequency = 220.0;
let maxFrequency = 880.0;
let freqRange = maxFrequency - minFrequency;
let thereminFreq = minFrequency + (x / theremin.clientWidth) * freqRange;
let thereminFreqRound = thereminFreq.toFixed(2);
let thereminVolume = 1.0 - (y / theremin.clientHeight);

if( autotune ) {
Expand All @@ -49,7 +52,7 @@ function thereminControl(e, oscillator, theremin) {
}
oscillator.frequency = thereminFreq;
var frequency = document.querySelector('#frequency .info');
frequency.innerHTML = thereminFreq;
frequency.innerHTML = thereminFreqRound;

oscillator.volume = thereminVolume;
var volumeElement = document.querySelector('#volume .info');
Expand Down

0 comments on commit b101998

Please sign in to comment.