牌語備忘録 -pygo

あくまでもメモです。なるべくオフィシャルの情報を参照してください。

牌語備忘録 -pygo

ギター指板の音名を覚えるためにリロードするとJavascriptでランダムに音名を表示してみるメモ

(追記2017-10-16)いまいち使い勝手が悪いので もっとシンプルなの書いた


音名

テンポ





(テンポ70~100、1~12フレット、6〜1〜6弦)

指板

f:id:CortYuming:20171003091329p:plain f:id:CortYuming:20170930225422p:plain

ソースコード

はてなブログの記事内に書くと動く。
参考リンク先からコードをいろいろ拝借(多謝)
(子どもの面倒見ながら書いてたからか改めて見るとひどいw グローバル変数とかw まあいいか。そのうちリファクタするかも)

音名

<script type="text/javascript">
var keys = ['C', 'C#/Db', 'D', 'D#/Eb', 'E', 'F', 'F#/Gb', 'G', 'G#/Ab', 'A', 'A#/Bb', 'B'];
function random(arr) {
  return arr[Math.floor(Math.random() * arr.length)];
}
document.write('<b style="font-size:200%;">' + random(keys) + '</b>');
</script>

テンポ

<button id="beat_on_70">start 70</button></br>
<button id="beat_on_80">start 80</button></br>
<button id="beat_on_90">start 90</button></br>
<button id="beat_on_100">start 100</button></br>
<button id="beat_off" style="margin-top:5px;">stop</button>

<script type="text/javascript">
var metronome = {
  intervals: [],
  play: function play(tempo, beat){
    var low = "UklGRnoGAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQoGAACBhYqFbF1fdJivrJBhNjVgodDbq2EcBj+a2/LDciUFLIHO8tiJNwgZaLvt559NEAxQp+PwtmMcBjiR1/LMeSwFJHfH8N2QQAoUXrTp66hVFApGn+DyvmwhBTGH0fPTgjMGHm7A7+OZSA0PVqzn77BdGAg+ltryxnMpBSl+zPLaizsIGGS57OihUBELTKXh8bllHgU2jdXzzn0vBSF1xe/glEILElyx6OyrWBUIQ5zd8sFuJAUuhM/z1YU2Bhxqvu7mnEoODlOq5O+zYBoGPJPY88p2KwUme8rx3I4+CRZiturqpVITC0mi4PK8aB8GM4nU8tGAMQYfcsLu45ZFDBFYr+ftrVoXCECY3PLEcSYELIH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h9y/HajDwJFmS46+mjUhEKTKLh8btmHwU1i9Xyz34wBiFzxfDglUMMEVux5+2sWhYIQprd88NvJAUsgs/y1oY3Bxpqve3mnUsODlKp5PC1YhsGOpHY88p5KwUlecnw3Y8+ChVgtunqp1QTCkig4PG9ayEEMojT89GBMgUfb8Lv4pdGDRBXr+fur1wXB0CX2/PEcycFKn/M8diKOQgZZrvs56BPEAxOpePxt2UcBzaP1vLOfC0FJHbH79+RQQsUXbTo7KlXFAlFnd7xwG4jBS+F0fLUhDQGHG3A7uSbSg0PVKrl7rJfGQc9lNn0yHUpBCh7yvLajTsJFmS46umkUREMSqPh8btoHgY0i9Tz0H4wBiFzw+/hlUULEVqw6O2sWhYIQprc88NxJQUsgs/y1oY3BxpqvO7mnUwPDVKo5PC1YhsGOpHY8sp5KwUleMjx3Y9ACRVgterqp1QTCkig3/K+aiEGMYjS89GBMgceb8Hu45lHDBBXrebvr1wYBz+Y2/PGcigEKn/M8dqJOwgZZrrs6KFOEAxOpd/js2coGUCLydq6e0MlP3uwybiNWDhEa5yztJRrS0lnjKOkk3leWGeAlZePfHRpbH2JhoJ+fXl9TElTVEQAAABJTkZPSUNSRAsAAAAyMDAxLTAxLTIzAABJRU5HCwAAAFRlZCBCcm9va3MAAElTRlQQAAAAU291bmQgRm9yZ2UgNC41AA==";
    var high = "UklGRnoGAABXQVZFZm10IBAAAAABAAEAQB8AAEAfAAABAAgAZGF0YQ0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000";
    var lowPlayer = new Audio("data:audio/wav;base64," + low);
    var highPlayer = new Audio("data:audio/wav;base64," + high);
    var volume = 0.3
    var lowInterval = setInterval(function(){
      lowPlayer.volume = volume;
      lowPlayer.play();
    }, 60 / tempo * 1000);
    var highInterval = setInterval(function(){
      highPlayer.volume = volume;
      highPlayer.play();
    }, 60 / tempo * 1000 * beat);

    metronome.intervals.push([lowInterval, highInterval]);

    return metronome;
  }
};
var beatOn70 = document.getElementById('beat_on_70');
var beatOn80 = document.getElementById('beat_on_80');
var beatOn90 = document.getElementById('beat_on_90');
var beatOn100 = document.getElementById('beat_on_100');
var beatOff = document.getElementById('beat_off');
metronome.stop = function() {
  for (const interval of metronome.intervals) {
    clearInterval(interval[0]);
    clearInterval(interval[1]);
  }
};
beatOn70.addEventListener('click', function() {
  metronome.stop();
  metronome.play(70, 4);
}, false);
beatOn80.addEventListener('click', function() {
  metronome.stop();
  metronome.play(80, 4);
}, false);
beatOn90.addEventListener('click', function() {
  metronome.stop();
  metronome.play(90, 4);
}, false);
beatOn100.addEventListener('click', function() {
  metronome.stop();
  metronome.play(100, 4);
}, false);
beatOff.addEventListener('click', function() {
  metronome.stop();
}, false);
</script>

元ネタの動画

これのランダムで音名表示と70~100のテンポで音をブログ記事内にJavascript書いてやってみる。

参考リンク