winsoundでマリオ

かなり適当

```python
import winsound
import time

### 音の長さ
ONE = 1.2
HALF = ONE/2
QUARTER = ONE/4
ONE_EIGTH = ONE/8
DOUBLE = ONE*2

### 音の周波数
TONES = {
    'ラ0': 27.5,
    'ラ' : 29.135,
    'シ0': 30.868,
    'ド1': 32.703,
    'ド#1': 34.648,
    'レ1': 36.708,
    'レ#1': 38.891,
    'ミ1': 41.203,
    'ファ1':43.654,
    'ファ#1':46.249,
    'ソ1': 48.999,
    'ソ#1': 51.913,
    'ラ1': 55,
    'ラ#1': 58.27,
    'シ1':61.735,
    'ド2': 65.406,
    'ド#2': 69.296,
    'レ2': 73.416,
    'レ#2': 77.782,
    'ミ2': 82.407,
    'ファ2': 87.307,
    'ファ#2': 92.499,
    'ソ2': 97.999,
    'ソ#2': 103.826,
    'ラ2': 110,
    'ラ#2': 116.541,
    'シ2': 123.471,
    'ド3': 130.813,
    'ド#3': 138.591,
    'レ3': 146.832,
    'レ#3': 155.563,
    'ミ3': 164.814,
    'ファ3': 174.614,
    'ファ#3': 184.997,
    'ソ3': 195.998,
    'ソ#3': 207.652,
    'ラ3': 220,
    'ラ#3': 233.082,
    'シ3': 246.942,
    'ド4': 261.626,
    'ド#4': 277.183,
    'レ4': 293.665,
    'レ#4': 311.127,
    'ミ4': 329.628,
    'ファ4': 349.228,
    'ファ#4': 369.994,
    'ソ4': 391.995,
    'ソ#4': 415.305,
    'ラ4': 440,
    'ラ#4': 466.164,
    'シ4': 493.883,
    'ド5': 523.251,
    'ド#5': 554.365,
    'レ5': 587.33,
    'レ#5': 622.254,
    'ミ5': 659.255,
    'ファ5': 698.456,
    'ファ#5': 739.989,
    'ソ5': 783.991,
    'ソ#5': 830.609,
    'ラ5': 880,
    'ラ#5': 932.328,
    'シ5': 987.767,
    'ド6': 1046.502,
    'ド#6': 1108.731,
    'レ6': 1174.659,
    'レ#6': 1244.508,
    'ミ6': 1318.51,
    'ファ6': 1396.913,
    'ファ#6': 1479.978,
    'ソ6': 1567.982,
    'ソ#6': 1661.219,
    'ラ6': 1760,
    'ラ#6': 1864.655,
    'シ6': 1975.533,
    'ド7': 2093.005,
    'ド#7': 2217.461,
    'レ7': 2349.318,
    'レ#7': 2489.016,
    'ミ7': 2637.02,
    'ファ7': 2793.826,
    'ファ#7': 2959.955,
    'ソ7': 3135.963,
    'ソ#7': 3322.438,
    'ラ7': 3520,
    'ラ#7': 3729.31,
    'シ7': 3951.066,
    'ド8': 4186.009
}

### 曲の配列[周波数,時間]
MARIO = [
    [['ミ4'], QUARTER],
    [['ミ4'], QUARTER],
    [['ミ4'], QUARTER],
    [['ド4'], QUARTER],
    [['ミ4'], QUARTER],
    [['ソ4'], QUARTER],
    [['休み'], HALF],
    [['ソ3'], QUARTER],
    [['休み'], QUARTER],
    [['ド4'], QUARTER],
    [['ソ3'], QUARTER],
    [['ミ3'], QUARTER],
    [['ラ3'], QUARTER],
    [['シ3'], QUARTER],
    [['ラ#3'], QUARTER],
    [['ラ3'], QUARTER],
    [['ソ3'], QUARTER],
    [['ミ4'], QUARTER],
    [['ソ4'], QUARTER],
    [['ラ4'], QUARTER],
    [['ファ4'], QUARTER],
    [['ソ4'], QUARTER],
    [['ミ4'], QUARTER],
    [['ド4'], QUARTER],
    [['レ4'], QUARTER],
    [['シ3'], QUARTER],
    [['休み'], QUARTER],
    [['ド4'], QUARTER],
    [['ソ3'], QUARTER],
    [['ミ3'], QUARTER],
    [['ラ3'], QUARTER],
    [['シ3'], QUARTER],
    [['ラ#3'], QUARTER],
    [['ラ3'], QUARTER],
    [['ソ3'], QUARTER],
    [['ミ4'], QUARTER],
    [['ソ4'], QUARTER],
    [['ラ4'], QUARTER],
    [['ファ4'], QUARTER],
    [['ソ4'], QUARTER],
    [['ミ4'], QUARTER],
    [['ド4'], QUARTER],
    [['レ4'], QUARTER],
    [['シ3'], QUARTER],
    [['ソ4'], QUARTER],
    [['ファ#4'], QUARTER],
    [['ファ4'], QUARTER],
    [['レ#4'], QUARTER],
    [['ミ4'], QUARTER],
    [['休み'], QUARTER],
    [['ソ3'], QUARTER],
    [['ラ3'], QUARTER],
    [['ド4'], QUARTER],
    [['休み'], ONE_EIGTH],
    [['ラ3'], QUARTER],
    [['ド4'], QUARTER],
    [['レ4'], QUARTER],
    [['休み'], ONE_EIGTH],
    [['ソ4'], QUARTER],
    [['ファ#4'], QUARTER],
    [['ファ4'], QUARTER],
    [['レ#4'], QUARTER],
    [['ミ4'], QUARTER],
    [['休み'], QUARTER],
    [['ド5'], QUARTER],
    [['ド5'], QUARTER],
    [['ド5'], QUARTER],
    [['休み'], HALF],
    [['ソ4'], QUARTER],
    [['ファ#4'], QUARTER],
    [['ファ4'], QUARTER],
    [['レ#4'], QUARTER],
    [['ミ4'], QUARTER],
    [['休み'], QUARTER],
    [['ソ3'], QUARTER],
    [['ラ3'], QUARTER],
    [['ド4'], QUARTER],
    [['休み'], ONE_EIGTH],
    [['ラ3'], QUARTER],
    [['ド4'], QUARTER],
    [['レ4'], QUARTER],
    [['休み'], ONE_EIGTH],
    [['ソ4'], QUARTER],
    [['ファ#4'], QUARTER],
    [['ファ4'], QUARTER],
    [['レ#4'], QUARTER],
    [['ミ4'], QUARTER],
    [['休み'], QUARTER],
    [['ド5'], QUARTER],
    [['ド5'], QUARTER],
    [['ド5'], QUARTER],
    [['休み'], HALF],
    [['ソ4'], QUARTER],
    [['ファ#4'], QUARTER],
    [['ファ4'], QUARTER],
    [['レ#4'], QUARTER],
    [['ミ4'], QUARTER],
    [['休み'], QUARTER],
    [['ソ3'], QUARTER],
    [['ラ3'], QUARTER],
    [['ド4'], QUARTER],
    [['休み'], ONE_EIGTH],
    [['ラ3'], QUARTER],
    [['ド4'], QUARTER],
    [['レ4'], QUARTER],
    [['休み'], ONE_EIGTH],
    [['レ#4'], QUARTER],
    [['休み'], ONE_EIGTH],
    [['レ4'], QUARTER],
    [['休み'], ONE_EIGTH],
    [['ド4'], QUARTER],
    [['ド4'], QUARTER],
    [['ド4'], QUARTER],
    [['ド4'], QUARTER],
    [['ド4'], QUARTER],
    [['レ4'], QUARTER],
    [['休み'], ONE_EIGTH],
    [['ミ4'], QUARTER],
    [['ド4'], QUARTER],
    [['ラ3'], QUARTER],
    [['ソ3'], QUARTER],
    [['休み'], HALF],
    [['ド4'], QUARTER],
    [['ド4'], QUARTER],
    [['ド4'], QUARTER],
    [['ド4'], QUARTER],
    [['レ4'], QUARTER],
    [['ミ4'], QUARTER],
    [['休み'], HALF],
    [['ド4'], QUARTER],
    [['ド4'], QUARTER],
    [['ド4'], QUARTER],
    [['ド4'], QUARTER],
    [['レ4'], QUARTER],
    [['休み'], ONE_EIGTH],
    [['ミ4'], QUARTER],
    [['ド4'], QUARTER],
    [['ラ3'], QUARTER],
    [['ソ3'], QUARTER],
    [['休み'], HALF],
    [['ミ4'], QUARTER],
    [['ミ4'], QUARTER],
    [['ミ4'], QUARTER],
    [['ド4'], QUARTER],
    [['ミ4'], QUARTER],
    [['ソ4'], QUARTER],
    [['休み'], HALF],
    [['ソ3'], QUARTER],
    [['休み'], QUARTER],
    [['ド4'], QUARTER],
    [['ソ3'], QUARTER],
    [['ミ3'], QUARTER],
    [['ラ3'], QUARTER],
    [['シ3'], QUARTER],
    [['ラ#3'], QUARTER],
    [['ラ3'], QUARTER],
    [['ソ3'], QUARTER],
    [['ミ4'], QUARTER],
    [['ソ4'], QUARTER],
    [['ラ4'], QUARTER],
    [['ファ4'], QUARTER],
    [['ソ4'], QUARTER],
    [['ミ4'], QUARTER],
    [['ド4'], QUARTER],
    [['レ4'], QUARTER],
    [['シ3'], QUARTER],
    [['休み'], QUARTER],
    [['ド4'], QUARTER],
    [['ソ3'], QUARTER],
    [['ミ3'], QUARTER],
    [['ラ3'], QUARTER],
    [['シ3'], QUARTER],
    [['ラ#3'], QUARTER],
    [['ラ3'], QUARTER],
    [['ソ3'], QUARTER],
    [['ミ4'], QUARTER],
    [['ソ4'], QUARTER],
    [['ラ4'], QUARTER],
    [['ファ4'], QUARTER],
    [['ソ4'], QUARTER],
    [['ミ4'], QUARTER],
    [['ド4'], QUARTER],
    [['レ4'], QUARTER],
    [['シ3'], QUARTER],
    [['ミ4'], QUARTER],
    [['ド4'], QUARTER],
    [['ソ3'], QUARTER],
    [['ソ#3'], QUARTER],
    [['ラ3'], QUARTER],
    [['ファ4'], QUARTER],
    [['ファ4'], QUARTER],
    [['ラ3'], QUARTER],
    [['休み'], QUARTER],
    [['シ3'], QUARTER],
    [['ラ4'], QUARTER],
    [['ラ4'], QUARTER],
    [['ラ4'], QUARTER],
    [['ソ4'], QUARTER],
    [['ファ4'], QUARTER],
    [['休み'], ONE_EIGTH],
    [['ミ4'], QUARTER],
    [['ド4'], QUARTER],
    [['ラ3'], QUARTER],
    [['ソ3'], QUARTER],
    [['休み'], HALF],
    [['ミ4'], QUARTER],
    [['ド4'], QUARTER],
    [['ソ3'], QUARTER],
    [['ソ#3'], QUARTER],
    [['ラ3'], QUARTER],
    [['ファ4'], QUARTER],
    [['ファ4'], QUARTER],
    [['ラ3'], QUARTER],
    [['休み'], ONE_EIGTH],
    [['シ3'], QUARTER],
    [['ファ4'], QUARTER],
    [['ファ4'], QUARTER],
    [['ミ4'], QUARTER],
    [['レ4'], QUARTER],
    [['ド4'], QUARTER],
    [['休み'], ONE],
    [['ド4'], QUARTER],
    [['ソ3'], QUARTER],
    [['ミ3'], QUARTER],
    [['ラ3'], HALF],
    [['シ3'], HALF],
    [['ラ3'], HALF],
    [['ソ#3'], HALF],
    [['ラ#3'], HALF],
    [['ソ#3'], ONE],
    [['ソ3'], DOUBLE]
]

### 演奏クラス
class Perform:
    melody = []

    def __init__(self, melody):
        self.melody = melody

    #def generate_tone(self, tones, beat, bpm=120):
    def generate_tone(self, tones, sec):
        """リストの音を再生
        Args:
            tones: 生成する音の周波数
            sec: 再生時間
        """
        for tone in tones:
            f = TONES[tone] if tone in TONES else 0
            if f != 0:
                #リストに存在する音であれば出力
                winsound.Beep(int(f), int(sec*1000))
            else:
                #リストに周波数は存在しないが時間が存在する場合は休止
                time.sleep(sec)

    def perform(self):
        #セットした楽譜をスピーカーで再生
        for note in self.melody:
            print(note)
            self.generate_tone(*note)

### 演奏する
rec = Perform(MARIO)
rec.perform()
```