Skip to content

Commit 3ebfb0c

Browse files
committed
token
1 parent 981716c commit 3ebfb0c

File tree

6 files changed

+123
-95
lines changed

6 files changed

+123
-95
lines changed

.eslintignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
src/bundle.js
2+
src/controller.js
23
src/ref/*.js

jsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"exclude": [
1111
"node_modules",
1212
"src/bundle.js",
13+
"src/controller.js",
1314
"src/ref"
1415
]
1516
}

src/bundle.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/controller.js

Lines changed: 104 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,109 @@
1-
const canvasElement = document.getElementById('canvas')
2-
const canvasContext = canvasElement.getContext('2d')
3-
const WIDTH = canvasElement.width = window.innerWidth
4-
const HEIGHT = canvasElement.height = 512
5-
6-
let audioCtx = new AudioContext()
7-
let analyser = audioCtx.createAnalyser()
8-
analyser.smoothingTimeConstant = 0.0
9-
analyser.fftSize = 1024
10-
11-
let bufferLength = analyser.frequencyBinCount
12-
let eightBufferLength = 8 * bufferLength
13-
let dataArray = new Uint8Array(bufferLength)
14-
15-
let imageDataFrame = canvasContext.createImageData(2, canvasElement.height)
16-
for (let i = 0; i < imageDataFrame.data.length * 4; i += 8) {
17-
for(let j = 3; j <= 7; j++) {
18-
imageDataFrame.data[i + j] = 255 // = 0,0,0,255|255,255,255,255
1+
;(() => {
2+
const vscode = acquireVsCodeApi()
3+
const oldState = vscode.getState()
4+
5+
const canvasElement = document.getElementById('canvas')
6+
const canvasContext = canvasElement.getContext('2d')
7+
const WIDTH = (canvasElement.width = window.innerWidth)
8+
const HEIGHT = (canvasElement.height = 512)
9+
// let currentCount = (oldState && oldState.count) || 0;
10+
11+
// setInterval(() => {
12+
// counter.textContent = currentCount++;
13+
14+
// // Update state
15+
// vscode.setState({ count: currentCount });
16+
17+
// // Alert the extension when the cat introduces a bug
18+
// if (Math.random() < Math.min(0.001 * currentCount, 0.05)) {
19+
// // Send a message back to the extension
20+
// vscode.postMessage({
21+
// command: 'alert',
22+
// text: '🐛 on line ' + currentCount
23+
// });
24+
// }
25+
// }, 100);
26+
27+
// Handle messages sent from the extension to the webview
28+
window.addEventListener('message', event => {
29+
const message = event.data // The json data that the extension sent
30+
switch (message.command) {
31+
case 'refactor':
32+
currentCount = Math.ceil(currentCount * 0.5)
33+
counter.textContent = currentCount
34+
break
35+
}
36+
})
37+
38+
let audioCtx = new AudioContext()
39+
let analyser = audioCtx.createAnalyser()
40+
analyser.smoothingTimeConstant = 0.0
41+
analyser.fftSize = 1024
42+
43+
let bufferLength = analyser.frequencyBinCount
44+
let eightBufferLength = 8 * bufferLength
45+
let dataArray = new Uint8Array(bufferLength)
46+
47+
let imageDataFrame = canvasContext.createImageData(2, canvasElement.height)
48+
for (let i = 0; i < imageDataFrame.data.length * 4; i += 8) {
49+
for (let j = 3; j <= 7; j++) {
50+
imageDataFrame.data[i + j] = 255 // = 0,0,0,255|255,255,255,255
51+
}
1952
}
20-
}
21-
22-
function getData() {
23-
let request = new XMLHttpRequest()
24-
request.open('GET', rootPath, true)
25-
request.responseType = 'arraybuffer'
26-
27-
request.onload = () => {
28-
var audioData = request.response
29-
30-
audioCtx.decodeAudioData(audioData, buffer => {
31-
32-
let offlineCtx = new OfflineAudioContext(2, buffer.length, 44100)
33-
let source = offlineCtx.createBufferSource()
34-
source.buffer = buffer
35-
36-
source.connect(offlineCtx.destination)
37-
source.start()
38-
39-
offlineCtx
40-
.startRendering()
41-
.then(renderedBuffer => {
42-
const song = audioCtx.createBufferSource()
43-
song.buffer = renderedBuffer
44-
45-
song.connect(audioCtx.destination)
46-
song.connect(analyser)
47-
// // play.onclick = function() {
48-
// song.playbackRate.value = 2
49-
song.start()
50-
// }
51-
song.onended = function(e) {
52-
console.log('finished')
53-
}
54-
analyser.getByteFrequencyData(dataArray)
55-
draw()
56-
})
57-
.catch(err => {
58-
console.log('Rendering failed: ' + err)
59-
// Note: The promise should reject when startRendering is called a second time on an OfflineAudioContext
60-
})
61-
})
53+
54+
function getData() {
55+
let request = new XMLHttpRequest()
56+
request.open('GET', rootPath, true)
57+
request.responseType = 'arraybuffer'
58+
59+
request.onload = () => {
60+
var audioData = request.response
61+
62+
audioCtx.decodeAudioData(audioData, buffer => {
63+
let offlineCtx = new OfflineAudioContext(2, buffer.length, 44100)
64+
let source = offlineCtx.createBufferSource()
65+
source.buffer = buffer
66+
67+
source.connect(offlineCtx.destination)
68+
source.start()
69+
70+
offlineCtx
71+
.startRendering()
72+
.then(renderedBuffer => {
73+
const song = audioCtx.createBufferSource()
74+
song.buffer = renderedBuffer
75+
76+
song.connect(audioCtx.destination)
77+
song.connect(analyser)
78+
// // play.onclick = function() {
79+
// song.playbackRate.value = 2
80+
song.start()
81+
// }
82+
song.onended = function(e) {
83+
console.log('finished')
84+
}
85+
analyser.getByteFrequencyData(dataArray)
86+
draw()
87+
})
88+
.catch(err => {
89+
console.log('Rendering failed: ' + err)
90+
// Note: The promise should reject when startRendering is called a second time on an OfflineAudioContext
91+
})
92+
})
93+
}
94+
request.send()
6295
}
63-
request.send()
64-
}
6596

66-
getData()
97+
getData()
6798

68-
let x= 0
69-
function draw() {
70-
requestAnimationFrame(draw)
71-
analyser.getByteFrequencyData(dataArray)
72-
for (let i = 0, y = eightBufferLength; i < bufferLength; i++, y -= 8) {
73-
imageDataFrame.data[y] = dataArray[i]
99+
let x = 0
100+
function draw() {
101+
requestAnimationFrame(draw)
102+
analyser.getByteFrequencyData(dataArray)
103+
for (let i = 0, y = eightBufferLength; i < bufferLength; i++, y -= 8) {
104+
imageDataFrame.data[y] = dataArray[i]
105+
}
106+
canvasContext.putImageData(imageDataFrame, x, 0)
107+
x < WIDTH ? x++ : (x = 0)
74108
}
75-
canvasContext.putImageData(imageDataFrame, x, 0)
76-
x < WIDTH ? x++ : x = 0
77-
}
109+
})()

src/extension.js

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@ function activate(context) {
1515
// let files = vscode.workspace.findFiles('**/*', null, 100)
1616
// files.then(data => console.log(data), error => console.error(error))
1717

18-
const test = new tv.Treeview(context)
19-
20-
test.specViewer.onDidChangeSelection(file => {
21-
console.log(file)
22-
console.log(test.specViewer.selection)
23-
})
24-
18+
const specTV = new tv.Treeview(context)
2519

2620
// vscode.workspace.onDidChangeConfiguration()
2721

@@ -33,6 +27,13 @@ function activate(context) {
3327
// And restric the webview to only loading content from our extension's `media` directory.
3428
// localResourceRoots: [vscode.Uri.file(path.join(extensionPath, 'media'))]
3529
})
30+
31+
specTV.specViewer.onDidChangeSelection(file => {
32+
if(specTV.specViewer.selection.indexOf('.mp3') != -1)
33+
wv.webview.postMessage(specTV.specViewer.selection)
34+
})
35+
36+
3637
const song_path = (vscode.Uri.file(path.join(context.extensionPath, 'beat.mp3'))).with({scheme: 'vscode-resource'})
3738
const bundle_uri = (vscode.Uri.file(path.join(context.extensionPath, 'src', 'bundle.js'))).with({scheme: 'vscode-resource'})
3839
const ctmcss_uri = (vscode.Uri.file(path.join(context.extensionPath, 'src', 'custom.css'))).with({scheme: 'vscode-resource'})

src/treeview.js

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,11 @@ const vscode = require('vscode')
33
const path = require('path')
44
const fs = require('fs')
55

6-
76
class Treeview {
87
constructor(context) {
9-
const treeDataProvider = new SpecTreeDataProvider(
10-
vscode.workspace.rootPath
11-
)
12-
context.subscriptions.push(vscode.workspace.registerTextDocumentContentProvider('spec', treeDataProvider));
13-
this.specViewer = vscode.window.createTreeView('spec', { treeDataProvider });
14-
8+
const treeDataProvider = new SpecTreeDataProvider(vscode.workspace.rootPath)
9+
context.subscriptions.push(vscode.workspace.registerTextDocumentContentProvider('spec', treeDataProvider))
10+
this.specViewer = vscode.window.createTreeView('spec', { treeDataProvider })
1511
}
1612
}
1713

@@ -37,23 +33,21 @@ class SpecTreeDataProvider {
3733
}
3834

3935
if (element) {
40-
return this.getFiles(path.join(element.filePath, element.label))
41-
36+
return this.getFiles(path.join(element.filePath, element.label))
4237
} else {
4338
return this.getFiles(this.workspaceRoot)
4439
}
4540
}
4641

4742
getFiles(thePath) {
48-
const toFileItem = (name, path, type) =>{
43+
const toFileItem = (name, path, type) => {
4944
if (type == 'directory') {
5045
let descriptionText, collapsibleState
51-
const filesCount = (fs.readdirSync(`${path}\\${name}`).filter(this.isMp3)).length
52-
if(filesCount > 0) {
46+
const filesCount = fs.readdirSync(`${path}\\${name}`).filter(this.isMp3).length
47+
if (filesCount > 0) {
5348
collapsibleState = vscode.TreeItemCollapsibleState.Collapsed
5449
descriptionText = `${filesCount} song`
55-
if(filesCount > 1) descriptionText += 's'
56-
50+
if (filesCount > 1) descriptionText += 's'
5751
} else {
5852
collapsibleState = vscode.TreeItemCollapsibleState.None
5953
descriptionText = 'Empty'
@@ -72,7 +66,6 @@ class SpecTreeDataProvider {
7266
const mp3filesItem = mp3s.map(name => toFileItem(name, thePath, 'mp3'))
7367

7468
return subdirsItem.concat(mp3filesItem)
75-
7669
}
7770

7871
isMp3(name) {

0 commit comments

Comments
 (0)