Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>  
<script src="https://cagpie.github.io/resources/smf/picotune-demo.mid.js"></script>
<script src="https://unpkg.com/picoaudio/dist/browser/PicoAudio.js"></script>
</head>
<body>
  <div>
    <input type="button" value="play" id="play-button" />
  </div>
  <div>
    <div class="sushi" id="sushi">🍣</div>
  </div>
</body>
</html>
 
// View
const playButton = document.getElementById('play-button')
// PicoAudio.jsの初期化
const picoAudio = new PicoAudio()
picoAudio.init()
// 曲データの初期化
const parsedSMF = picoAudio.parseSMF(picotuneDemoSmf)
picoAudio.setData(parsedSMF)
// playボタンで再生状態を初期化して再生する
playButton.addEventListener('click', () => {
  picoAudio.initStatus()
  picoAudio.play()
})
///////////////////////////////////////////////////////
// View
const sushi = document.getElementById('sushi')
// 寿司の位置
let x = 0
// PicoAudioのイベントリスナ
picoAudio.addEventListener('noteOn', (note) => {
  // チャンネル0(メロディ)だけ見る
  if (note.channel === 0) {
    x += 10
    sushi.style.transform = `translateX(${x % 300}px)`
  }
})
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
cagpiepro
0viewers