Skip to content

Commit

Permalink
Add noisy returns
Browse files Browse the repository at this point in the history
  • Loading branch information
1j01 committed Aug 8, 2018
1 parent e56cd28 commit d52d5d8
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 4 deletions.
10 changes: 9 additions & 1 deletion src/Fretboard.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,13 @@ class @Fretboard

prevent = (e)->
e.preventDefault()
no
return false

update_pointer_position = (e)=>
offset = $canvas.offset()
@pointerX = e.pageX - offset.left
@pointerY = e.pageY - offset.top
return

$$.on "pointermove", update_pointer_position

Expand All @@ -124,13 +125,15 @@ class @Fretboard
prevent(e)
$canvas.focus()
$$.on "pointermove", prevent # make it so you don't select text in the textarea when dragging from the canvas
return

$$.on "pointerup blur", (e)=>
$$.off "pointermove", prevent # but let you drag other times
@pointerDown = off
@pointerOpen = off
@pointerBend = off
string.release() for string in @strings
return

# @TODO: pointercancel/blur/Esc

Expand All @@ -147,6 +150,7 @@ class @Fretboard
# @fret_scale = Math.sqrt(@canvas.width) * 50
@fret_scale = Math.min(Math.sqrt(@canvas.width) * 50, 2138)
# @x = OSW + Math.max(0, (@canvas.width - @w)/2) # to center it
return

draw: =>
ctx = @canvas.getContext("2d")
Expand All @@ -160,6 +164,7 @@ class @Fretboard
ctx.moveTo(x1, y1)
ctx.lineTo(x2, y2)
ctx.stroke()
return

drawBentLine = (x1, y1, x2, y2, controlPointXOffset, controlPointYOffset, ss, lw)=>
ctx.strokeStyle = ss if ss?
Expand All @@ -172,6 +177,7 @@ class @Fretboard
x2, y2
)
ctx.stroke()
return

drawVibratingString = (x1, y1, x2, y2, stringAmplitudeData, ss, lw)=>
amplitudeToPixels = 3
Expand Down Expand Up @@ -202,6 +208,7 @@ class @Fretboard

drawBentLine(x1, y1, x2, y2, 0, yBend, ss, lw)
ctx.restore()
return

drawFingerHoldOrOpenNote = (fretX, fretW, stringY, stringHeight, stringBendY=0)=>
ctx.beginPath()
Expand All @@ -217,6 +224,7 @@ class @Fretboard
ctx.fillRect(fretX + 5 - fretW, stringY - stringHeight/2, fretW - 5, stringHeight)
ctx.fillRect(fretX - 5, stringY - stringHeight/2, 10, stringHeight)
ctx.fill()
return

ctx.save()
ctx.translate(@x, @y)
Expand Down
1 change: 1 addition & 0 deletions src/GuitarString.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class @GuitarString
@data = e.outputBuffer.getChannelData(0)
for i in [0..@data.length]
@data[i] = @getSampleData()
return
@script_processor.connect(pre)

@started = no
Expand Down
11 changes: 10 additions & 1 deletion src/TablatureEditor.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ class @TablatureEditor
@positions.push column
last_column_had_digit = column_has_digit
column++

return

# The following is based on the default multi-selection block selection code:
# https://github.com/ajaxorg/ace/blob/master/lib/ace/mouse/multi_select_handler.js
Expand Down Expand Up @@ -116,6 +118,7 @@ class @TablatureEditor
rectSel.forEach(@editor.addSelectionMarker, @editor)
@editor.updateSelectionMarkers()
@editor.$blockScrolling--
return


@editor.$blockScrolling++
Expand Down Expand Up @@ -148,13 +151,15 @@ class @TablatureEditor
@editor.inVirtualSelectionMode = false
@editor.$mouseHandler.$clickSelection = null
@editor.$blockScrolling--
return

onSelectionInterval = blockSelect

event.capture(@editor.container, onMouseSelection, onMouseSelectionEnd)
timerId = setInterval(onSelectionInterval, 20)

return e.preventDefault()
e.preventDefault()
return

showPlayingNote: (pos, note)->
@removePlayingNote(pos, note)
Expand All @@ -165,11 +170,13 @@ class @TablatureEditor
range = new Range(note.s, column, note.s, column+1)
marker = @editor.getSession().addMarker(range, "playing-note", "text") # text?
@playing_note_highlight_markers[key] = marker
return

removePlayingNote: (pos, note)->
key = "#{note.s}:#{pos}"
existing_marker = @playing_note_highlight_markers[key]
@editor.getSession().removeMarker existing_marker if existing_marker
return

showPlaybackPosition: (pos)->
column = @positions[pos]
Expand All @@ -190,9 +197,11 @@ class @TablatureEditor
# delta_pageX = pageX_2 - pageX_1
# @editor.renderer.scrollToX column * delta_pageX
# @editor.renderer.scrollToX column * 7
return

hidePlaybackPosition: ->
for marker in @column_highlight_markers
@editor.getSession().removeMarker marker

@column_highlight_markers = []
return
25 changes: 23 additions & 2 deletions src/app.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
@tuning = "eBGDAE" # backwards
@strings = ("#{string_name}|-" for string_name in @tuning)
@pos = 0
return

toJSON: -> @notes
toString: -> song.strings.join("\n")
Expand All @@ -25,6 +26,7 @@

if song.notes.length is 1
tablature_editor.showPlaybackPosition(song.pos)
return

song.clear()

Expand Down Expand Up @@ -55,11 +57,13 @@ do update_scale_highlighting = ->
else
scale_notes = teoria.scale(scale_start, scale_name).notes()
scale_midi_values = (scale_note.midi() % 12 for scale_note in scale_notes)
return

# disable_outside_scale = disable_outside_scale_checkbox.checked
# disable_outside_scale_checkbox.onchange = (e)->
# disable_outside_scale = e.target.checked
# update_scale_highlighting()
# return

scale_select.addEventListener "change", update_scale_highlighting
scale_start_select.addEventListener "change", update_scale_highlighting
Expand All @@ -85,32 +89,42 @@ tablature_presets_select.addEventListener "change", (e)->
load_tablature(tabs_text)
xhr.open "GET", path
xhr.send()
return


@fretboard = new Fretboard()
$(fretboard.canvas).appendTo(".fretboard-area")

$tablature_error = $(".tablature-error")
$tablature_error.dismiss = -> @hide().attr("aria-hidden", "true").text("")
$tablature_error.message = (message)-> @show().attr("aria-hidden", "false").text(message)
$tablature_error.dismiss = ->
@hide().attr("aria-hidden", "true").text("")
return
$tablature_error.message = (message)->
@show().attr("aria-hidden", "false").text(message)
return

tablature_editor = new TablatureEditor($(".tablature-editor")[0])
tablature_editor.showPlaybackPosition(song.pos)

undo_button.addEventListener "click", ->
tablature_editor.editor.undo()
return
redo_button.addEventListener "click", ->
tablature_editor.editor.redo()
return

do update_multi_row_selection_mode = ->
tablature_editor.multi_row_selection_mode = multi_row_selection_mode_input.checked
return
multi_row_selection_mode_input.addEventListener "change", update_multi_row_selection_mode

do update_overwrite_mode = ->
tablature_editor.editor.session.setOverwrite(overwrite_mode_input.checked)
return
overwrite_mode_input.addEventListener "change", update_overwrite_mode
tablature_editor.editor.session.on "changeOverwrite", ->
overwrite_mode_input.checked = tablature_editor.editor.session.getOverwrite()
return

$theme = $(".theme")

Expand All @@ -127,11 +141,13 @@ for theme_name, theme of Fretboard.themes
$theme.on "change", ->
fretboard.theme = Fretboard.themes[$theme.val()]
try localStorage.guitar_theme = $theme.val()
return


do animate = =>
fretboard.draw()
requestAnimationFrame(animate)
return


$$ = $(window)
Expand All @@ -141,6 +157,7 @@ $$.on "keyup", (e)->
sustain = off
for string in fretboard.strings
string.release()
return

$$.on "keydown", (e)->
key = e.keyCode
Expand Down Expand Up @@ -188,6 +205,8 @@ $$.on "keydown", (e)->
$$.off "keyup", onkeyup

tablature_editor.showPlaybackPosition(song.pos)
return
return

$$.on "blur", ->
string.stop() for string in fretboard.strings
Expand All @@ -198,6 +217,7 @@ $$.on "blur", ->
tablature_editor.editor.on "blur", ->
text = tablature_editor.editor.getValue()
load_tablature(text)
return

load_tablature = (text)->
if text isnt "#{song}" and text
Expand All @@ -224,3 +244,4 @@ load_tablature = (text)->
tablature_editor.showPlaybackPosition(song.pos)
else
$tablature_error.dismiss()
return
1 change: 1 addition & 0 deletions src/audio-setup.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ tuna = new Tuna(actx)
connect = (nodes...)->
for node, i in nodes when next = nodes[i+1]
node.connect next.input ? next.destination ? next
return

# # # # # # # # # # # #

Expand Down
1 change: 1 addition & 0 deletions src/tablature.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ parseTabs = (tablature)->
if current_block.tuning.toUpperCase() is tuning.toUpperCase()
current_block.tuning = tuning
current_block = null
return

for line in lines
if line.match(/[-–—]/)
Expand Down

0 comments on commit d52d5d8

Please sign in to comment.