Skip to content

Commit

Permalink
Merge pull request #2 from lazzarello/include-nexus-tutorial
Browse files Browse the repository at this point in the history
[Nexus UI Tutorial](https://nexus-js.github.io/ui/api/#intro), but for Vue.js with [async components](https://vuejs.org/v2/guide/components-dynamic-async.html#Async-Components) loading to enable the web audio context. The async stuff might not be needed when the [relevant PR is merged](nexus-js/ui#190).
  • Loading branch information
lazzarello authored Aug 11, 2020
2 parents eec7286 + 1c7a292 commit 54bcf1e
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 6 deletions.
5 changes: 5 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
},
"dependencies": {
"core-js": "^3.6.5",
"vue": "^2.6.11"
"vue": "^2.6.11",
"nexusui": "^2.0.13"
},
"devDependencies": {
"@vue/cli-plugin-babel": "~4.4.0",
Expand Down
8 changes: 6 additions & 2 deletions src/components/Scarlett.vue
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<div v-else>
<h1>Scarlett 18i8 Mixer</h1>
<p>Found Device: <tt>{{ info | findScarlett }}</tt></p>
<ScarlettMixer />
</div>
</section>
</div>
Expand Down Expand Up @@ -38,7 +39,7 @@
}
})
if ( found ) {
return outInfo.info
return outInfo.name
} else {
outInfo = {"error": "No Scarlett device found"}
return outInfo
Expand All @@ -55,6 +56,9 @@
})
.finally(() => this.loading = false)
},
name: 'Scarlett'
name: 'Scarlett',
components: {
'ScarlettMixer': () => import('./ScarlettMixer.vue')
}
}
</script>
72 changes: 72 additions & 0 deletions src/components/ScarlettMixer.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<template>
<div class="mixer">
<button v-on:click="pan1()">Load Mixer Controls</button>
<h1>I'm a ScarlettMixer!</h1>
<div id="channel">
<div id="pan"></div>
<div id="volume"></div>
<div id="outbus"></div>
</div>
<div id="debug">
<hr />
<h3>Debugging</h3>
<tt>{{ controls.data }}</tt>
</div>
</div>
</template>

<script>
import axios from 'axios'
var apiURL = 'http://localhost:1234/jsonapi?request=';
// https://nexus-js.github.io/ui/api/#intro
import Nexus from 'nexusui'
//we gotta seperate the actual rendering of NexusUI elements before the context is started
function loadAudio() {
Nexus.context.resume();
var pan = new Nexus.Pan('#pan');
var volume = new Nexus.Slider("#volume", {
'size': [20,200]
});
var outbus = new Nexus.Toggle('#outbus');
var channel = [pan, volume, outbus];
pan.on('change', function(v) {
console.log('Pan ' + v.value);
})
volume.on('change', function(v) {
console.log('Volume ' + v);
})
outbus.on('change', function(v) {
console.log('Channel ' + v);
})
return channel;
}
export default {
data () {
return {
controls: null,
loading: true,
errored: false,
pan1: loadAudio,
context: Nexus.context
}
},
mounted () {
// There can be more than one device named hw:USB
// I'll have to pass in cardid from a value from the Scarlett component
axios
.get(apiURL + 'ctrl-get-all' + '&cardid=hw:USB')
.then(response => (this.controls = response.data))
.catch(error => {
console.log(error)
this.errored = true
})
.finally(() => this.loading = false)
},
name: 'ScarlettMixer'
}
</script>
12 changes: 9 additions & 3 deletions src/main.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
import Vue from 'vue'
import './plugins/axios'
import App from './App.vue' // no data because we're not importing it?
// commenting this out removes the default template, which is a bit weird.
import App from './App.vue'
// eslint-disable-next-line no-unused-vars
import Nexus from 'nexusui'

Vue.config.productionTip = false;
//Vue.config.runtimeCompiler = true;
// Vue.config.runtimeCompiler = true;

// https://nexus-js.github.io/ui/api/#intro
// the following is a convention for defaults of Vue
// eslint-disable-next-line no-unused-vars
//var dial = new Nexus.Dial('#dial')

new Vue({
render: h => h(App),
Expand Down

0 comments on commit 54bcf1e

Please sign in to comment.