Skip to content

Commit c9adde3

Browse files
committed
added options for label and autoplay
1 parent 742d454 commit c9adde3

File tree

7 files changed

+98
-28
lines changed

7 files changed

+98
-28
lines changed

example/codeKeyframes.css

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

example/codeKeyframes.js

Lines changed: 37 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/codeKeyframes.min.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.

example/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
waveColor: '#3AEAD2',
6464
progressColor: '#0c9fa7',
6565
bgColor: '#222',
66+
label: 'Tracktitle Music: Artistname Visuals: Artistname',
67+
autoplay: true,
6668
keyframes: [] // paste in after exporting keyframes
6769
})
6870
</script>

src/html/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
waveColor: '#3AEAD2',
6464
progressColor: '#0c9fa7',
6565
bgColor: '#222',
66+
label: 'Tracktitle Music: Artistname Visuals: Artistname',
67+
autoplay: true,
6668
keyframes: [] // paste in after exporting keyframes
6769
})
6870
</script>

src/js/app/main.js

Lines changed: 37 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ function CodeKeyframes(args){
66
this.audioPath = args.audioPath
77
this.editorOpen = args.editorOpen || false
88
this.keyframes = args.keyframes || []
9+
this.label = args.label
10+
this.autoplay = args.autoplay || false
911

1012
this.activeRegion = null
1113
this.skipLength = 1
@@ -16,8 +18,8 @@ function CodeKeyframes(args){
1618
this.sequenceNextTime = null
1719

1820
document.querySelector('body').insertAdjacentHTML('beforeend',`
19-
<div id="cf-editor">
20-
<div id="cf-waveform" tabindex="0"></div>
21+
<div id="ckf-editor">
22+
<div id="ckf-waveform" tabindex="0"></div>
2123
<form class="code-form">
2224
<textarea name="code" id="code" cols="30" rows="10"></textarea>
2325
<div class="controls">
@@ -26,11 +28,18 @@ function CodeKeyframes(args){
2628
</form>
2729
</div>`)
2830

29-
this._editor = document.querySelector('#cf-editor')
30-
this._waveform = document.querySelector('#cf-editor #waveform')
31-
this._codeForm = document.querySelector('#cf-editor .code-form')
32-
this._code = document.querySelector('#cf-editor #code')
33-
this._renderButton = document.querySelector('#cf-editor .render')
31+
this._editor = document.querySelector('#ckf-editor')
32+
this._waveform = document.querySelector('#ckf-editor #waveform')
33+
this._codeForm = document.querySelector('#ckf-editor .code-form')
34+
this._code = document.querySelector('#ckf-editor #code')
35+
this._renderButton = document.querySelector('#ckf-editor .render')
36+
37+
if( this.label ){
38+
_label = document.createElement('div')
39+
_label.innerHTML = this.label
40+
_label.classList.add('ckf-label')
41+
this._editor.appendChild(_label)
42+
}
3443

3544
if( !this.editorOpen ){
3645
this._editor.classList.add('closed')
@@ -122,7 +131,10 @@ function CodeKeyframes(args){
122131
start: this.wavesurfer.getCurrentTime(),
123132
end: this.wavesurfer.getCurrentTime()+0.1,
124133
drag: false,
125-
resize: false
134+
resize: false,
135+
data:{
136+
code:this._code.value
137+
}
126138
})
127139

128140
this.editCode(region)
@@ -133,6 +145,7 @@ function CodeKeyframes(args){
133145
// space
134146
32:()=>{
135147
this.wavesurfer.playPause()
148+
this._code.classList.remove('error')
136149
},
137150

138151
// page up
@@ -359,7 +372,7 @@ function CodeKeyframes(args){
359372
var progressColor = args.progressColor || '#0c9fa7'
360373

361374
this.wavesurfer = WaveSurfer.create({
362-
container: '#cf-waveform',
375+
container: '#ckf-waveform',
363376
height: waveHeight,
364377
scrollParent: true,
365378
normalize: true,
@@ -380,6 +393,11 @@ function CodeKeyframes(args){
380393

381394
// build the sequence
382395
this.updateSequence()
396+
397+
// autoplay
398+
if(this.autoplay){
399+
this.wavesurfer.play()
400+
}
383401
})
384402

385403
this.wavesurfer.on('region-click', (region) => {
@@ -397,13 +415,21 @@ function CodeKeyframes(args){
397415
if( !command ) return
398416
if( time > command.time ){
399417
this.sequenceCursor++
400-
eval(command.code)
418+
419+
this._code.classList.remove('error')
420+
421+
try{
422+
eval(command.code)
423+
} catch(error){
424+
this._code.classList.add('error')
425+
console.log(error)
426+
}
427+
401428

402429
// find the region to show
403430
var regions = this.wavesurfer.regions.list
404431
for( var key in regions){
405432
if( regions[key].start == command.time ){
406-
407433
this.editCode(regions[key], false)
408434
break
409435
}

src/scss/style.scss

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,23 @@
1-
#cf-editor{
1+
#ckf-editor{
22
background-color: #222;
33
position: fixed;
44
bottom: 0;
55
left: 0;
66
width: 100%;
77
font-family: monaco, monospace;
88
-webkit-font-smoothing:antialiased;
9+
10+
.ckf-label{
11+
position: absolute;
12+
bottom: 100%;
13+
left: 0;
14+
font-size: 10px;
15+
background-color: inherit;
16+
color:#fff;
17+
padding: 0 5px 0 2px;
18+
}
919

10-
#cf-waveform{
20+
#ckf-waveform{
1121
height: 150px;
1222

1323
&:focus, &:active{
@@ -25,7 +35,7 @@
2535
}
2636

2737
&.closed{
28-
#cf-waveform{
38+
#ckf-waveform{
2939
height: 70px;
3040

3141
>wave{
@@ -82,6 +92,9 @@
8292
outline:none;
8393
background-color: #333;
8494
}
95+
&.error{
96+
color:#ff6666;
97+
}
8598
}
8699

87100
.controls{
@@ -94,7 +107,8 @@
94107
padding: 10px;
95108
text-transform: uppercase;
96109
border-bottom: 1px solid #ccc;
97-
font-size: 12px;
110+
font-size: 10px;
111+
width: 140px;
98112
}
99113
}
100114
}

0 commit comments

Comments
 (0)