Skip to content

Commit

Permalink
Added sounddevice enumeration
Browse files Browse the repository at this point in the history
  • Loading branch information
tim37021 committed Jun 2, 2017
1 parent c5a3012 commit ed0f178
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 14 deletions.
7 changes: 6 additions & 1 deletion pages/editor-main/editor-main.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@
</div>
<div class="dropdown" style="width: 120px; height: 25px; margin: 13px 0px 10px 10px;">
<div style="width: 100px; margin-left: 8px; margin-top: 2px; font-size: 18px;" id="downdown_selection" onclick="this.nextElementSibling.style.display=null; event.stopPropagation()">cc</div>
<div class="dropdown-content" style="width: 120px; display: none;" id="deviceSelection">
<div class="dropdown-content" style="width: 120px; display: none;" id="comDeviceSelection">
</div>
</div>
<div class="dropdown" style="width: 200px; height: 25px; margin: 13px 0px 10px 10px;">
<div style="width: 100px; margin-left: 8px; margin-top: 2px; font-size: 18px;" id="downdown_selection" onclick="this.nextElementSibling.style.display=null; event.stopPropagation()">cc</div>
<div class="dropdown-content" style="width: 120px; display: none;" id="audioDeviceSelection">
</div>
</div>
</div>
Expand Down
61 changes: 48 additions & 13 deletions pages/editor-main/script/editor-main.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const dialog = remote.dialog;
var assert = require('assert');
var pythonBridge = require('python-bridge')


document.querySelector('#openfile').addEventListener('click', openDialog)
document.querySelector('#saveas').addEventListener('click', saveDialog)
document.querySelector('#recordbtn').addEventListener('click', record)
Expand All @@ -25,12 +24,34 @@ function msgbox(title, msg) {
msgbox.style.display = null
}

python_cmd = checkPythonVersion()
function checkPythonVersion() {
try {
var python = pythonBridge({python: 'python3', env: {PYTHONPATH: './tools'}})
python.end()
return 'python3'
} catch (err) {
}
try {
var python = pythonBridge({python: 'python', env: {PYTHONPATH: './tools'}})
python.ex`import sys`
python`sys.version_info.major == 2`.then(x => {
if(x)
msgbox("錯誤", "Python版本不符,最低需求版本>=3.0.0")
})
python.end()
return 'python'
} catch (err) {
msgbox("錯誤", "Python尚未安裝,最低需求版本>=3.0.0")
}
return undefined
}

function record() {
var device = document.getElementById('deviceSelection').parentElement.children[0].innerHTML
console.log(device)
var python = pythonBridge({python: 'python3', env: {PYTHONPATH: './tools'}})
python.ex`import slimtabdriver`
python`slimtabdriver.SliMTABDriver(${device}).check()`.then(x => {if(!x) msgbox("錯誤", "沒有權限存取裝置或者裝置不存在")})
var device = document.getElementById('comDeviceSelection').parentElement.children[0].innerHTML
var python = pythonBridge({python: python_cmd, env: {PYTHONPATH: './tools/SLiMTAB-backend'}})
python.ex`import SlimTabDriver`
python`SlimTabDriver.SliMTABDriver(${device}).check()`.then(x => {if(!x) msgbox("錯誤", "沒有權限存取裝置或者裝置不存在")})
python.end()
}

Expand All @@ -39,18 +60,32 @@ function print() {
}

setInterval(function() {
var selection = document.getElementById('deviceSelection')
if(selection.style.display == "none") {
var python = pythonBridge({python: 'python3', env: {PYTHONPATH: './tools'}})
selection.innerHTML = ''
python.ex`import slimtabdriver`
python`slimtabdriver.list_com_ports()`.then(x => {
var com = document.getElementById('comDeviceSelection')
var python = pythonBridge({python: python_cmd, env: {PYTHONPATH: './tools/SLiMTAB-backend'}})
if(com.style.display == "none") {
com.innerHTML = ''
python.ex`import SlimTabDriver`
python`SlimTabDriver.list_com_ports()`.then(x => {
x.forEach(function (name) {
e = document.createElement("a");
e.setAttribute('onclick', 'this.parentElement.parentElement.children[0].innerHTML=this.innerHTML')
e.innerHTML = name
selection.appendChild(e)
com.appendChild(e)
})
})
}
var audio = document.getElementById('audioDeviceSelection')
if(audio.style.display == "none") {
audio.innerHTML = ''
python.ex`import SlimTabManager`
python`SlimTabManager.SlimTabManager().getInputDevicesName()`.then(x => {
x.forEach(function (name) {
e = document.createElement("a");
e.setAttribute('onclick', 'this.parentElement.parentElement.children[0].innerHTML=this.innerHTML')
e.innerHTML = name
audio.appendChild(e)
})
})
}
python.end()
}, 1000)

0 comments on commit ed0f178

Please sign in to comment.