<script src="https://cdn.jsdelivr.net/npm/@coderline/alphatab@latest/dist/alphaTab.js"></script>
<button id="play">
Play
</button>
<div id="alphaTab">
</div>
CSS
/* Styles for player */
.at-cursor-bar {
/* Defines the color of the bar background when a bar is played */
background: rgba(255, 242, 0, 0.25);
}
.at-selection div {
/* Defines the color of the selection background */
background: rgba(64, 64, 255, 0.1)
}
.at-cursor-beat {
/* Defines the beat cursor */
background: rgba(64, 64, 255, 0.75);
width: 3px;
}
.at-highlight * {
/* Defines the color of the music symbols when they are being played (svg) */
fill: #0078ff;
stroke: #0078ff;
}
.at-selection-handles {
position : absolute;
pointer-events: none;
z-index: 1001;
display: inline;
top: 0;
left: 0;
right: 0;
bottom: 0;
}
.at-selection-handle {
position : absolute;
pointer-events: auto;
cursor: ew-resize;
background: #7cb9ff;
width: 4px;
opacity: 0;
transition: opacity 150ms ease-in-out;
display: none;
}
.at-selection-handle:hover,
.at-selection-handle.at-selection-handle-drag {
opacity: 1;
}
.at-selection-handle.active {
display: block;
}
.at-selection-handle-drag * {
cursor: ew-resize !important;
}
TypeScript
// Just to make JS Fiddle happy some Types
declare namespace alphaTab {
type AlphaTabApi = any;
namespace model {
type Beat = any;
}
namespace rendering {
type BeatBounds = any;
}
}
const alphaTab = (globalThis as any).alphaTab;
// end of JS Fiddle types
const el = document.getElementById('alphaTab');
let at = new alphaTab.AlphaTabApi(el, {
player: {
enablePlayer: true,
soundFont:
'https://cdn.jsdelivr.net/npm/@coderline/alphatab@alpha/dist/soundfont/sonivox.sf2',
},
});
function createSelectionHandles(element: HTMLElement): { startHandle: HTMLElement; endHandle: HTMLElement } {
const handleWrapper = document.createElement('div');
handleWrapper.classList.add('at-selection-handles');
element.insertBefore(handleWrapper, element.querySelector('at-surface'));
const startHandle = document.createElement('div');
startHandle.classList.add('at-selection-handle', 'at-selection-handle-start');
handleWrapper.appendChild(startHandle);
const endHandle = document.createElement('div');
endHandle.classList.add('at-selection-handle', 'at-selection-handle-end');
handleWrapper.appendChild(endHandle);
return { startHandle, endHandle };
}
interface HandleDragState {
isDragging: 'start' | 'end' | undefined;
}
function setupHandleDrag(
element: HTMLElement,
handle: HTMLElement,
dragState: HandleDragState,
type: HandleDragState['isDragging'],
onMove: (e: MouseEvent) => void,
onDragEnd: (e: MouseEvent) => void
) {
handle.addEventListener(
'mousedown',
e => {
e.preventDefault();
element.classList.add('at-selection-handle-drag');
handle.classList.add('at-selection-handle-drag');
dragState.isDragging = type;
},
false
);
document.addEventListener(
'mousemove',
e => {
if (dragState.isDragging !== type) {
...
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Fiddle Pages
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Get Fiddle Pages with PRO
Your fiddles accessible under a custom domain and a vanity path - the simplest hosting for your personal project.