Clean up and comment out functions to help explain
This commit is contained in:
parent
8d181d9931
commit
11f9d7aa57
@ -5,59 +5,71 @@
|
|||||||
// https://developer.mozilla.org/en-US/docs/web/javascript/reference
|
// https://developer.mozilla.org/en-US/docs/web/javascript/reference
|
||||||
//
|
//
|
||||||
|
|
||||||
// TODO: Read this from the environment so it can run propoerly
|
var serverUrl = "http://localhost:5000"; // TODO: read from environment
|
||||||
// depending on whether it is in development or production mode
|
|
||||||
var serverUrl = "http://localhost:5000";
|
|
||||||
var archiveUrl = serverUrl + "/add-to-archive/";
|
var archiveUrl = serverUrl + "/add-to-archive/";
|
||||||
|
var microphone;
|
||||||
var mic, recorder, soundFile;
|
var recorder;
|
||||||
|
var recording;
|
||||||
var recordingTimeout = 30000; // 30 seconds (in milliseconds)
|
var recordingTimeout = 30000; // 30 seconds (in milliseconds)
|
||||||
var shouldGenerateNewShape = false;
|
var newSoundJustRecorded = false;
|
||||||
|
var shapes = [];
|
||||||
|
|
||||||
|
function doRecording() {
|
||||||
|
/**
|
||||||
|
* Starting recording.
|
||||||
|
**/
|
||||||
|
if (microphone.enabled) {
|
||||||
|
setTimeout(recorder.record(recording), recordingTimeout);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function doStopping() {
|
||||||
|
/**
|
||||||
|
* Stop recording a new recording.
|
||||||
|
**/
|
||||||
|
if (recorder.recording) {
|
||||||
|
recorder.stop();
|
||||||
|
newSoundJustRecorded = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function doPlaying() {
|
||||||
|
/**
|
||||||
|
* Play the recording.
|
||||||
|
**/
|
||||||
|
if (recording.isLoaded()) {
|
||||||
|
recording.play();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function doArchiving() {
|
||||||
|
/**
|
||||||
|
* Send the recording to the back-end.
|
||||||
|
**/
|
||||||
|
var soundBlob = recording.getBlob();
|
||||||
|
|
||||||
|
var httpRequestOptions = {
|
||||||
|
method: "POST",
|
||||||
|
body: new FormData().append("soundBlob", soundBlob),
|
||||||
|
headers: new Headers({ enctype: "multipart/form-data" })
|
||||||
|
};
|
||||||
|
|
||||||
|
httpDo(archiveUrl, httpRequestOptions); // TODO: add error handling and fix
|
||||||
|
}
|
||||||
|
|
||||||
function setupRecording() {
|
function setupRecording() {
|
||||||
mic = new p5.AudioIn();
|
/**
|
||||||
mic.start();
|
* Setup logic for recording.
|
||||||
|
**/
|
||||||
|
microphone = new p5.AudioIn();
|
||||||
|
microphone.start();
|
||||||
|
|
||||||
recorder = new p5.SoundRecorder();
|
recorder = new p5.SoundRecorder();
|
||||||
recorder.setInput(mic);
|
recorder.setInput(microphone);
|
||||||
|
|
||||||
soundFile = new p5.SoundFile();
|
recording = new p5.SoundFile();
|
||||||
|
|
||||||
function doRecording() {
|
// TODO: buttons are just for experimenting ...
|
||||||
if (mic.enabled) {
|
|
||||||
setTimeout(recorder.record(soundFile), recordingTimeout);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function doStopping() {
|
|
||||||
if (recorder.recording) {
|
|
||||||
recorder.stop();
|
|
||||||
shouldGenerateNewShape = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function doPlaying() {
|
|
||||||
if (soundFile.isLoaded()) {
|
|
||||||
soundFile.play();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function doArchiving() {
|
|
||||||
var soundBlob = soundFile.getBlob();
|
|
||||||
|
|
||||||
var httpRequestOptions = {
|
|
||||||
method: "POST",
|
|
||||||
body: new FormData().append("soundBlob", soundBlob),
|
|
||||||
headers: new Headers({ enctype: "multipart/form-data" })
|
|
||||||
};
|
|
||||||
|
|
||||||
// TODO: do error handling when things fail
|
|
||||||
// TODO: this doesn't actually work right now
|
|
||||||
httpDo(archiveUrl, httpRequestOptions);
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO: we'll probably want something more glam than
|
|
||||||
// some default buttons but that's fine for experimenting
|
|
||||||
recordButton = createButton("record");
|
recordButton = createButton("record");
|
||||||
recordButton.position(10, 90);
|
recordButton.position(10, 90);
|
||||||
recordButton.mousePressed(doRecording);
|
recordButton.mousePressed(doRecording);
|
||||||
@ -75,36 +87,41 @@ function setupRecording() {
|
|||||||
playButton.mousePressed(doArchiving);
|
playButton.mousePressed(doArchiving);
|
||||||
}
|
}
|
||||||
|
|
||||||
function collectSoundParamters() {
|
function getSoundInfo() {
|
||||||
// TODO: collect all the sound parameters
|
/**
|
||||||
// [x] amplitude
|
* Retrieve sound information like pitch, amplitude, duration, etc.
|
||||||
// [x] length of sound
|
**/
|
||||||
// [ ] pitch
|
amplitude = recording.getPeaks();
|
||||||
// [ ] nuance
|
duration = recording.duration();
|
||||||
// btw, there is no "nuance" function for p5js. My current guess is to
|
// pitch?
|
||||||
// perhaps measure it from the "getPeaks". For all wave peaks measured,
|
// nuance?
|
||||||
// ??? (need to think this through, not really sure ...)
|
|
||||||
amplitude = soundFile.getPeaks();
|
|
||||||
duration = soundFile.duration();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function generateShape() {
|
function generateNewShape() {
|
||||||
// TODO: take in sound parameters and generate a shape
|
/**
|
||||||
ellipse(100, 100, 25, 25);
|
* Create a new p5.js shape.
|
||||||
|
**/
|
||||||
|
ellipse(100, 100, 25, 25); // TODO: experimenting for now ...
|
||||||
}
|
}
|
||||||
|
|
||||||
function setup() {
|
function setup() {
|
||||||
// TODO: Replace this with the leaflet/mappa setup just
|
/**
|
||||||
// using this for now to draw something to experiment on
|
* The p5.js initial setup function.
|
||||||
createCanvas(600, 600);
|
**/
|
||||||
|
createCanvas(600, 600); // TODO: experimenting for now ...
|
||||||
setupRecording();
|
setupRecording();
|
||||||
}
|
}
|
||||||
|
|
||||||
function draw() {
|
function draw() {
|
||||||
if (shouldGenerateNewShape) {
|
/**
|
||||||
collectSoundParamters();
|
* The p5.js draw loop.
|
||||||
generateShape();
|
**/
|
||||||
shouldGenerateNewShape = false;
|
if (newSoundJustRecorded === true) {
|
||||||
|
shapes.push(generateNewShape());
|
||||||
|
newSoundJustRecorded = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var shape of shapes) {
|
||||||
|
shape.display();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user