hydra-synth / hydra

Livecoding networked visuals in the browser
https://hydra.ojack.xyz
GNU Affero General Public License v3.0
2.16k stars 264 forks source link

Capture video into a source buffer #26

Closed echophon closed 5 years ago

echophon commented 6 years ago

After seeing https://webrtc.github.io/samples/src/content/getusermedia/record/ I think this could be interesting to capture short loops into one of the source buffer (s0, s1, s2, s3) for further manipulation

IE I could record a short clip from the webcam and loop it, as opposed to taking the live webcam feed constantly.

This could also be used to 'bounce down' heavy processing which could help keep framerates up

Similar to #10 but more oriented toward live capture.

ojack commented 6 years ago

This actually already exists! but i hadnt mentioned it because i wasn't sure about the api/possibly has some bugs.

// run this line to start recording
vidRecorder.start()

// stop recording
vidRecorder.stop()

// set the output video as a source
s0.init({src: vidRecorder.output})

// display the source
src(s0).out()
echophon commented 6 years ago

This is great. Looking forward to playing with this. I'm a test engineer, so finding bugs is sort of my thing. Happy to provide feedback on experimental builds. Speaking of which- I saw that there was some NanoKontrol support for a bit but removed later on? I'm interested in that!

ojack commented 6 years ago

i put in a nanokontrol package mainly because i was performing with a nanokontrol! but then it caused build problems at some point and i took it out. But it turns out the web midi api is pretty straight forward without using any packages. THis is code to initialize webmidi, you can then inspect the values and see what corresponds to what on your midi controller, and use that to change a variable.

navigator.requestMIDIAccess()
    .then(onMIDISuccess, onMIDIFailure);
//
function onMIDISuccess(midiAccess) {
    console.log(midiAccess);
    var inputs = midiAccess.inputs;
    var outputs = midiAccess.outputs;
    for (var input of midiAccess.inputs.values()){
        input.onmidimessage = getMIDIMessage;
    }
}
//
function onMIDIFailure() {
    console.log('Could not access your MIDI devices.');
}
//

getMIDIMessage = function(midiMessage) {
    var data = midiMessage.data
   /// do something with the data
}
ojack commented 6 years ago

I have used it to control the cutoff and scale of the microphone input so that I can adjust as the music changes. this is code for doing that using the nanokontrol:

cutoffMult = 10
scaleMult = 1.5
getMIDIMessage = function(midiMessage) {
    var arr = midiMessage.data
    var val = arr[2]
    var index = arr[1]
    if(arr[1] < 4) {
      a.settings[index].cutoff = val/cutoffMult
    }
    if(arr[1] > 15 && arr[2] < 20) a.settings[arr[1]-16].scale = val/scaleMult
}
ojack commented 5 years ago

I am going to close this because it exists!