#!/usr/bin/env python import csnd6 import pygame.midi as md import os md.init() #[[[241, 0, 0, 0], 4244]] # 0 = 24 fps # 1 = 25 fps # 2 = 29.97 drop frame # 3 = 29.97 non-drop frame # 6 = 30 drop # 7 = 30 non-drop # 0b000 = 29.97 0b100 = 30 fps = 1 if fps == 0: mps = 96 lim = 24 bits = 0 elif fps == 1: mps = 100 lim = 25 bits = 1 elif fps == 2: mps = 119.88 lim = 30 bits = 2 elif fps == 3: mps = 119.88 lim = 30 bits = 3 elif fps == 6: mps = 120 lim = 30 bits = 2 else: mps = 120 lim = 30 bits = 3 orc = ''' sr = 44100 ksmps = 16 nchnls = 2 pyinit gimessagerate = ''' + str(mps) + ''' instr 1 setksmps 1 kcount init 0 ktrig metro gimessagerate ckgoto (ktrig == 0), nothing pycall "midisendmtcrt", kcount kcount += 1 nothing: endin ''' ############ sco = ''' f0 22 i1 0 20 ''' count = 0 frame = 0 sec = 0 minute = 0 hour = 0 change = 0 sendtime = 0 msglist = [] scorelen = 20 while sendtime <= scorelen: leftbits = count << 4 if (count == 0): rightbits = frame % 16 elif (count == 1): rightbits = frame >> 4 elif (count == 2): rightbits = int(sec % 60) % 16 elif (count == 3): rightbits = int(sec % 60) >> 4 elif (count == 4): rightbits = (int(minute % 60)) % 16 elif (count == 5): rightbits = int(minute % 60) >> 4 elif (count == 6): rightbits = (int(hour % 24)) % 16 elif (count == 7): hourrightbits = int(hour) % 24 >> 4 rightbits = hourrightbits + (bits << 1) if (bits == 2) and (frame == 28) and (sec == 59) and ((minute % 10) != 0): ### drop-frame frame = 2 change = 1 else: frame = (frame + 2) % lim if frame < 2: change = 1 else: change = 0 if change == 1: sec = (sec + 1) % 60 if sec == 0: minute = (minute + 1) % 60 if minute == 0: hour = (hour + 1) % 24 byte = leftbits + rightbits msglist.append(byte) sendtime += 1.0/mps count = (count + 1) % 8 #print msglist def midisendmtcrt(byte): # print byte player.mout.write([[[241, int(msglist[int(byte)]), 0, 0], md.time()]]) pass player = csnd6.CppSound() player.mout = md.Output(10) player.SetOption("-m0d") # Using SetOption() to configure Csound player.SetOption("-+rtaudio=portaudio") player.SetOption("-odac0") player.SetOption("-b 4") player.CompileOrc(orc) player.ReadScore(sco) player.Start() while (player.PerformKsmps() == 0): pass player.Perform() player.Stop() #outfile.close() del player.mout del player