All Projects → feross → bg-sound

feross / bg-sound

Licence: MIT License
Web Component to emulate the old-school <bgsound> HTML element

Programming Languages

javascript
184084 projects - #8 most used programming language
HTML
75241 projects

Projects that are alternatives of or similar to bg-sound

Romplayer
AudioKit Sample Player (ROM Player) - EXS24, Sound Font, Wave Player
Stars: ✭ 445 (+378.49%)
Mutual labels:  midi, sound
Webmidikit
Simplest MIDI Swift library
Stars: ✭ 100 (+7.53%)
Mutual labels:  midi, sound
Webaudiofont
Use full GM set of musical instruments to play MIDI and single sounds or effects. Support for reverberation and equaliser. No plugins, no Flash. Pure HTML5 implementation compatible with desktop and mobile browser. See live examples.
Stars: ✭ 600 (+545.16%)
Mutual labels:  midi, sound
Awesome Music Production
A curated list of software, services and resources to create and distribute music.
Stars: ✭ 340 (+265.59%)
Mutual labels:  midi, sound
smart-custom-element
Smart a lightweight web component library that provides capabilities for web components, such as data binding, using es6 native class inheritance. This library is focused for providing the developer the ability to write robust and native web components without the need of dependencies and an overhead of a framework.
Stars: ✭ 17 (-81.72%)
Mutual labels:  web-components, html-element
Minibae
The platform-neutral Beatnik Audio Engine, Mini Edition (miniBAE) is an exceptionally mature, well-rounded, and reliable computer music and sound system specially customized for small-footprint and embedded applications.
Stars: ✭ 82 (-11.83%)
Mutual labels:  midi, sound
Audiokitsynthone
AudioKit Synth One: Open-Source iOS Synthesizer App
Stars: ✭ 1,258 (+1252.69%)
Mutual labels:  midi, sound
Wad
Web Audio DAW. Use the Web Audio API for dynamic sound synthesis. It's like jQuery for your ears.
Stars: ✭ 1,540 (+1555.91%)
Mutual labels:  midi, sound
Shape-Your-Music
A web application for drawing music.
Stars: ✭ 106 (+13.98%)
Mutual labels:  midi, sound
Html Midi Player
🎹 Play and display MIDI files on the web
Stars: ✭ 158 (+69.89%)
Mutual labels:  midi, web-components
libDaisy
Hardware Library for the Daisy Audio Platform
Stars: ✭ 164 (+76.34%)
Mutual labels:  midi, sound
linux-show-player
Linux Show Player - Cue player designed for stage productions
Stars: ✭ 147 (+58.06%)
Mutual labels:  midi, sound
DMXOPL
YMF262-enhanced FM patch set for Doom and source ports.
Stars: ✭ 42 (-54.84%)
Mutual labels:  midi, sound
custom-elements-manifest
Custom Elements Manifest is a file format that describes custom elements in your project.
Stars: ✭ 81 (-12.9%)
Mutual labels:  web-components
ws-ldn-12
ARM / STM32F7 DIY synth workshop
Stars: ✭ 62 (-33.33%)
Mutual labels:  midi
cwco
Powerful and Fast Web Component Library with a Simple API
Stars: ✭ 27 (-70.97%)
Mutual labels:  web-components
birdseye
Next generation component catalog
Stars: ✭ 41 (-55.91%)
Mutual labels:  web-components
SoundProcesses
A computer music framework to describe, create and manage sound processes in the Scala programming language. Issue tracker: https://codeberg.org/sciss/SoundProcesses/issues
Stars: ✭ 29 (-68.82%)
Mutual labels:  sound
ionic-custom-components
🌈 Ionic Tutorial: Mastering Web Components in Ionic Framework. This repo is an Ionic project showcasing Angular custom components and Stencil custom web components.
Stars: ✭ 30 (-67.74%)
Mutual labels:  web-components
ANMP
multi-channel loopable video game music player for nerds and audiophiles
Stars: ✭ 16 (-82.8%)
Mutual labels:  midi

bg-sound

travis npm downloads javascript style guide

Web Component to emulate the old-school <bgsound> HTML element

Play MIDI files in a browser with a simple Web Component, emulating <bgsound>, the Background Sound element.

Install

npm install bg-sound

This package works in the browser with browserify. If you do not use a bundler, you can use the standalone script directly in a <script> tag.

Usage

Add a custom HTML element called <bg-sound>:

<script src="bg-sound.min.js"></script>
<bg-sound src="sound.mid"></bg-sound>

Automatically make legacy <bgsound> and <embed> HTML tags work:

<!-- Must include *BEFORE* all <bgsound> and <embed> tags -->
<script src="../bg-sound.min.js"></script>
<script>BgSound.enableCompatMode()</script>

<!-- All of the following HTML tags now work! -->
<bgsound src="goldensun.mid">
<embed src="goldensun.mid">
<embed src="mario-death.mid" loop="2">
<embed src="sound.wav">
<embed src="sound.wav" loop=true>

Talk

I introduced this project in a talk at JSConf Colombia 2018.

The Lost Art of MIDI talk

  • Slides
  • Talk video (coming soon!)

FAQ

Why is the tag called <bg-sound> (with a dash)?

The name of a custom HTML element must contain a dash (-). This is what the spec says, presumably because otherwise browsers could not introduce new HTML tags without web compatibility risk.

Why is the script tag required?

The script tag is needed to define the behavior of the <bg-sound> HTML element. Without it, the browser would just treat the tag like a <div>.

Where do the WebAssembly code and instrument sound files come from?

By default, these files will load remotely from BitMidi. This is nice for simple demos and quick hacks. However, it is recommended to host these files yourself. (I reserve the right to remove the CORS headers which allow this to work at any time if too much bandwidth is used.)

What are the timidity and freepats packages?

npm install timidity freepats

The <bg-sound> custom element lazily loads a WebAssembly file and instrument sounds at runtime.

The timidity package provides the WebAssembly file (libtimidity.wasm). The freepats package provides the instrument sound files.

It's important to ensure that the timidity and freepats folders in node_modules are being served to the public. For example, here is how to mount the necessary files at / with the express server:

const timidityPath = path.dirname(require.resolve('timidity'))
app.use(express.static(timidityPath))

const freepatsPath = path.dirname(require.resolve('freepats'))
app.use(express.static(freepatsPath))

Optionally, provide a baseUrl attribute to customize where the player will look for the lazy-loaded WebAssembly file libtimidity.wasm and the FreePats General MIDI soundset files. The default baseUrl is https://bitmidi.com/timidity/.

<bg-sound src="sound.mid" baseUrl="/custom-path"></bg-sound>

How do I automatically make legacy <bgsound> and <embed> tags work?

Include this code before any <bgsound> or <embed> HTML tags:

<!-- Must include *BEFORE* all <bgsound> and <embed> tags -->
<script src="../bg-sound.min.js"></script>
<script>BgSound.enableCompatMode()</script>

<!-- All of the following HTML tags now work! -->
<bgsound src="goldensun.mid">
<embed src="goldensun.mid">
<embed src="mario-death.mid" loop="2">
<embed src="sound.wav">
<embed src="sound.wav" loop=true>

If you want to provide your own baseUrl, then simply pass that into the BgSound.enableCompatMode() function call as follows:

BgSound.enableCompatMode({ baseUrl: '/custom-path' })

Demo

If you like this, then check out BitMidi.com, the wayback machine for old-school MIDI files! Check out some examples MIDIs here:

License

MIT. Copyright (c) Feross Aboukhadijeh.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].