Skip to content

Commit

Permalink
Add WebMidiLink html
Browse files Browse the repository at this point in the history
  • Loading branch information
ryohey committed Dec 28, 2017
1 parent a4f0e93 commit 97e7795
Show file tree
Hide file tree
Showing 14 changed files with 252 additions and 143 deletions.
16 changes: 7 additions & 9 deletions bin/sf2.parser.js

Large diffs are not rendered by default.

235 changes: 111 additions & 124 deletions bin/sf2.synth.js

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion export/parser.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
import Parser from "../src/Parser.ts"
export default Parser
export {
Parser
}
4 changes: 3 additions & 1 deletion export/synth.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
import WebMidiLink from "../src/WebMidiLink.ts"
export default WebMidiLink
export {
WebMidiLink
}
Binary file modified fixture/TestSoundFont.sf2
Binary file not shown.
Binary file removed fixture/clarinet_angel_pure_v1.1.sf2
Binary file not shown.
1 change: 1 addition & 0 deletions public/bin
1 change: 1 addition & 0 deletions public/fixture
22 changes: 22 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="./bin/sf2.synth.js"></script>
<script>
const url = './fixture/TestSoundFont.sf2'
const wml = new WebMidiLink()
wml.setLoadCallback(function(arraybuffer) {
// ロード完了時の処理
})
wml.setup(url)
</script>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="synth"></div>
</body>
</html>
99 changes: 99 additions & 0 deletions public/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
.synth {
font-size: 12px;
margin: 0;
background: rgb(0, 0, 0);
color: rgb(159, 159, 253);
font-family: Consolas;
overflow: hidden;
/* -webkit-app-region: drag; */
border-top: 1.5em rgba(255, 255, 255, 0.13) solid;
padding-top: 0.25em;
}

.synth .keys>div {
float: left;
}

.synth .keys>.white, .keys>.black {
position: relative;
}

.synth .keys {
overflow: hidden;
background: black;
-webkit-app-region: no-drag;
}

.synth .keys>.white {
width: 5px;
height: 20px;
background: rgb(85, 85, 90);
border-right: 1px solid black;
box-sizing: border-box;
}

.synth .keys>.black {
width: 3px;
background: rgb(0, 0, 0);
height: 11px;
left: 1px;
margin-left: -3px;
z-index: 999;
}

.synth .volume::before {content: "VOL:";}

.synth .panpot::before {content: "PAN:";}

.synth .pitchBend::before {content: "BEND:";}

.synth .pitchBendSensitivity::before {
content: "RANGE:";
}

.synth select {
background: transparent;
color: currentColor;
border: none;
outline: none;
font-family: Consolas;
width: 12em;
font-size: 100%;
-webkit-app-region: no-drag;
}

.synth option {
background: black;
color: rgb(159, 159, 253);
}

.synth .program, .volume, .panpot, .pitchBend, .pitchBendSensitivity {
display: inline-block;
}

.synth .key.white.note-on,
.synth .key.black.note-on {
background: rgb(246, 196, 78);
}

.synth h1 {
float: left;
font-size: 240%;
margin: 0 7px 0px 0;
}

.synth header p {
margin: 0;
}

.synth header {
overflow: hidden;
}

.synth header .version {
opacity: 0.7;
}

.synth button[disabled] {
opacity: 0.4;
}
6 changes: 3 additions & 3 deletions src/Parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface ParseResult {
sampleHeader: Sample[]
sample: Int16Array[]
samplingData: Chunk
info: {}
info: { [index: string]: string }
}

export default function parse(input: Uint8Array, option: RiffParserOptions = {}): ParseResult {
Expand Down Expand Up @@ -99,8 +99,8 @@ function getChunkList(chunk, data, expectedType, expectedSignature) {
return parseRiff(data, stream.ip, chunk.size - 4)
}

function parseInfoList(chunk: Chunk, data: Uint8Array): {} {
const info = {}
function parseInfoList(chunk: Chunk, data: Uint8Array) {
const info: { [index: string]: string } = {}
const chunkList = getChunkList(chunk, data, "LIST", "INFO")

for (let p of chunkList) {
Expand Down
3 changes: 0 additions & 3 deletions src/Structs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,6 @@ export class Sample {
}
}

/**
* @enum {number}
*/
export const SampleLink = {
monoSample: 1,
rightSample: 2,
Expand Down
3 changes: 2 additions & 1 deletion src/WebMidiLink.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ export default class WebMidiLink {
synth = this.synth = new Synthesizer(ctx)
synth.init()
synth.refreshInstruments(input)
synth.connect(ctx.destination)
const view = this.view = new View()
document.body.appendChild(view.draw(synth))
document.body.querySelector(".synth")!.appendChild(view.draw(synth))
this.midiMessageHandler.synth = synth
window.addEventListener('message', this.onmessage.bind(this), false)
} else {
Expand Down
1 change: 0 additions & 1 deletion webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ module.exports = {
output: {
path: path.join(__dirname, "bin"),
filename: "sf2.[name].js",
library: "[name]",
libraryTarget: "umd"
},
resolve: {
Expand Down

0 comments on commit 97e7795

Please sign in to comment.