0.6.0 • Published 5 years ago

webaudio-pianoroll v0.6.0

Weekly downloads
3
License
Apache-2.0
Repository
github
Last release
5 years ago

webaudio-pianoroll

Pianoroll GUI library for Web application / relevant to webaudio-controls

webaudio-pianoroll is a GUI library for pianoroll. Using webaudio-pianoroll with webaudio-controls makes it easy to build webaudio application.

webaudio-controls is here :
webaudio-controls

  • Editmode - webaudio-pianoroll has four edit mode, gridmono, gridpoly, dragmono and dragpoly. grid types are just toggle the grid cell by clicking, and the note length is always 1 tick. grid types matche to rhythm machine like app. The other hand, drag types can specify note length by dragging. that are matches generic pianoroll apps.
  • Many customize options.
  • Play support - webaudio-pianoroll has not direct sound generation function, but has play support function.

Live Demo page is available.

Live Demo : 'gridmono' mode

Live Demo : 'dragpoly' timebase=480 mode


Usage

The previous version was a module of Polymer, but now it is a normal JavaScript library using WebCompnents API.

Since webaudio-pianoroll uses only the functionality of WebComponents CustomElements, it works without webcomponents polyfill in Chrome and Firefox.

  • Install webaudio-pianoroll

    If you know bower, use the command > bower install g200kg/webaudio-pianoroll.
    This command prepares webaudio-pianoroll under your current folder.
    Otherwise, download zipped file and deploy appropriately. necessary file is webaudio-pianoroll.js.

    And load the webaudio-pianoroll.js :
    <script src="https://g200kg.github.io/webaudio-pianoroll/webaudio-pianoroll.js"></script>

    Or, just directory load from GitHub pages as CDN.
    <script src="https://g200kg.github.io/webaudio-pianoroll/webaudio-pianoroll.js"></script>

  • If needed, load webcomponents.js in your HTML.

    <script src="webcomponents-lite.min.js"></script>

  • place webaudio-pianoroll element in your HTML

    <webaudio-pianoroll></webaudio-pianoroll>

    In default, it makes element like this:
    npm.io

    Then you can customize the pianoroll with attributes. For example,
    <webaudio-pianoroll width="300" height="200" xrange="64" markend="64" collt="#33f" coldk="#338" editmode="dragmono"></webaudio-pianoroll>

    npm.io

How To Operate

Common

  • Time axis can be zoomed by mouse wheel if enabled by a "wheelzoom" attribute.

Grid Mode

  • The cell can be toggle on/off by clicking.
  • When dragging, you can turn on or off multiple cells depending on the state of the first cell.

Drag mode

  • Drag with the left button to create a specified length note.
  • Click existing note to select.
  • Drag with the right button to select notes within the specified area (Whether the note is included in the range or not is determined based on whether or not the beginning of the note is included).
  • Selected notes can be moved by left button dragging.
  • Drag the left or right edge of the selected note to change the length of the note.
  • Right click on the selected note to delete menu.

Attributes

AttributeOptionsDefaultDescription
widthNumber640width of element in px
heightNumber320height of element in px
editmodeString"gridmono"combination of "grid"/"drag" + "mono"/"poly"
timebaseNumber16time resolution of 1 bar, (1 bar / timebase = 1 tick)
xrangeNumber16time axis view range in tick
yrangeNumber16y axis view range in note number
xoffsetNumber0time axis offset in tick
yoffsetNumber60y axis offset in note number
gridNumber4time axis grid density in tick
snapNumber1note x position snapping in tick
wheelzoomNumber0if non 0, time axis zoom by wheel is enabled
xrulerNumber24time axis ruler height in px
yrulerNumber24y axis ruler width in px
octadjNumber-1ruler octave value adjust (-1 : 60=C4)
cursorNumber0current play position in tick
markstartNumber0play range start marker position in tick
markendNumber16play range end marker position in tick
colltString"#ccc"score background (light part) color
coldkString"#aaa"score background (dark part) color
colgridString"#666"score grid color
colnoteString"#f22"note color
colnoteselString"#0f0"selected note color (for editmode="drag")
colnoteborderString"#000"note border color
colrulerbgString"#666"ruler background color
colrulerfgString"#fff"ruler foreground color
colrulerborderString"#000"ruler border color
bgsrcStringnullbackground image url. To make visible this, you should set collt/coldk non-opaque with 'rgba(r,g,b,a)' style.
cursorsrcStringinternal resourceplaycursor image url
cursoroffsetNumber0playcursor image x offset in px
markstartsrcStringinternal resourcemarkstart image url
markstartoffsetNumber0markstart image x offset in px
markendsrcStringinternal resourcemarkend image url
markendoffsetNumber-24markend image x offset in px
kbsrcStringinternal resourcekeyboard image url
kbwidthNumber40keyboard image width in px
loopNumber1loop play
preloadNumber1data preload when play in sec
tempoNumber120tempo when play

Functions

FunctionDescription
redraw()redraw all
getMMLString()get MML string of current data. Note that this function is for mono type editmode.
setMMLString(str)set MML string to webaudio-pianoroll. Note that this function is for mono type editmode.
locate(tick)set cursor to specified tick
play(audioContext, callback, starttick)play current data. webaudio-pianoroll does not generate sound directly, but it passes necessary information to the specified callback function. audioContext is used to control the time axis. If starttick is not specified, play from current cursor position.

Callback

play() function passes necessary data for playing to callback function like : callback({t:noteOnTime, g:noteOffTime, n:noteNumber})

Here the noteOnTime and noteOffTime is audioContext timeline value.

DataStructure

If you want to access directly to sequence data, you can touch the DOMElement.sequence.

DOMElement.sequence is an Array of noteEvents. Here the noteEvent is a object of one note infomation of:
{t:noteOnTick g:noteLength n:noteNumber}

License

webaudio-pianoroll is licensed under the Apache License, Version 2.0