Skip to content

Commit

Permalink
init commit
Browse files Browse the repository at this point in the history
  • Loading branch information
matsuo committed Aug 21, 2014
1 parent 7e7c49c commit 1800dbc
Show file tree
Hide file tree
Showing 4 changed files with 412 additions and 0 deletions.
80 changes: 80 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,83 @@ miku.js
=======

JavaScript library for using NSX-39 with Web MIDI.

## How to use

```JavaScript
// get instance
Miku.init(function(miku) {
// set lyrics
miku.lyrics('', '', '', '', '');

// play
miku.noteOn(69, 127);

// stop
miku.noteOff(69, 0);
});
```

## API

### Set lyrics

Send MIDI message to set lyrics.

```JavaScript
// Array of String
miku.lyrics(['', '', '', '', '']);

// Separated by space
miku.lyrics('あ い う え お');

// Separated by comma
miku.lyrics('こ,ん,に,ち,わ');

// unknown character is ignored
miku.lyrics('み t ddd く');
```

### Play note

```JavaScript
var noteNumber = 60,
velocity = 64;
miku.noteOn(noteNumber, velocity);

...

miku.noteOff(noteNumber, velocity);
```

### Send other MIDI message

```JavaScript
// bend value is 0 to 16384. Default value is 8192.
miku.pitchBend(4096);

// Modulation
miku.controlChange(1, 127);
```

### Event listening

These events are also emitted from MIDI Input.

```JavaScript
miku.on('noteOn', function(noteNum, velocity) {
console.log('Note on', noteNum, velocity);
});

miku.on('noteOff', function(noteNum, velocity) {
console.log('Note off', noteNum, velocity);
});

miku.on('pitchBend', function(value) {
console.log('Pitch bend', value);
});

miku.on('sysEx', function(dataArray) {
console.log('sys ex', dataArray);
});
```
21 changes: 21 additions & 0 deletions bower.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"name": "miku",
"main": "miku.js",
"version": "0.0.1",
"authors": [
"matsuo <[email protected]>"
],
"description": "JavaScript library for using NSX-39 with Web MIDI.",
"keywords": [
"miku",
"hatsune"
],
"license": "MIT",
"ignore": [
"**/.*",
"node_modules",
"bower_components",
"test",
"tests"
]
}
78 changes: 78 additions & 0 deletions demo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<!DOCTYPE html>

<html>
<head>
<title>miku.js - demo</title>
</head>
<body>

<input type="text" id="lyrics" value="こ ん に ち わ">
<button onclick="setLyrics()">Set</button>

<button onclick="noteOn(60)">C</button>
<button onclick="noteOn(62)">D</button>
<button onclick="noteOn(64)">E</button>
<button onclick="noteOn(65)">F</button>
<button onclick="noteOn(67)">G</button>
<button onclick="noteOn(69)">A</button>
<button onclick="noteOn(71)">B</button>

<script src="miku.js"></script>
<script>
var miku, timer;

Miku.init(function(instance) {
miku = instance;
setLyrics();

miku.on('noteOn', function(noteNum, velocity) {
console.log('note on', noteNum, velocity);
}).on('pitchBend', function(bend1, bend2) {
console.log('bend', bend1, bend2);
}).on('noteOff', function(noteNum, velocity) {
console.log('note off', noteNum, velocity);
}).on('sysEx', function(data) {
console.log('sys ex', data);
});
});

function setLyrics() {
var lyrics = document.getElementById('lyrics').value
miku.lyrics(lyrics);
}

function noteOn(num) {
miku.noteOn(num, 64);

clearTimeout(timer);

timer = setTimeout(function() {
miku.noteOff(num, 0);
}, 1000)
}

// send pitch bend test
var pitch = 8192;
document.addEventListener('keydown', function(e) {
switch (e.keyCode) {
case 37:
miku.controlChange(1, 0);
break;
case 38:
pitch += 128;
miku.pitchBend(pitch);
break;
case 39:
miku.controlChange(1, 127);
break;
case 40:
pitch -= 128;
miku.pitchBend(pitch);
break;
}
});


</script>
</body>
</html>
Loading

0 comments on commit 1800dbc

Please sign in to comment.