from buzz import *

bpm = 0
tpb = 0
sps = 0
spt = 0
pit = 0
tps = 0
mpt = 0
spb = 0

def master_status():
    global bpm, tpb, sps, spt, pit, tps
    bpm, tpb, sps, spt, pit, tps = GetMasterInfo()

def get_mpt():
    global sps, tpb, tps, mpt
    single = sps / 1000.000
    mpt = tps / single

def display_calcs():
    global mpt, tpb, spb, tps, sps, spt
    get_mpt()
    spb = mpt * tpb
    bar = spb * tpb
    print mpt, 'sec. per tick',
    print spb, 'sec.  per beat'    
    print 'len  1\\32  1\\24  1\\16  1\\12  1\\8  1\\6  1\\4  1\\3  1\\2'
    print 'ms  %5d %5d %5d %5d %4d %4d %4d %4d %4d' % (int((bar / 32.0) * 1000), int((bar / 24.0) * 1000), int((bar / 16.0) * 1000), \
            int((bar / 12.0) * 1000), int((bar / 8.0) * 1000), int((bar / 6.0) * 1000), int((bar / 4.0) * 1000), \
            int((bar / 3.0)* 1000), int((bar / 2.0) * 1000))
    hpt = (sps * bar) / (tpb)
    print 'LFO: 1 tick', hpt / tpb, '1 beat', hpt / (tpb * tpb), '1/2 bar', hpt / (tpb * (tpb * 2))


def display():
    global bpm, tpb, sps, spt, tps, mpt
    print bpm, 'BPM @', tpb, 'TPB'
    print sps, 'sampsPerSec', spt, 'sampsPerTick', tps, 'ticksPerSecond'
    display_calcs()
        
def OnMasterInfoChange():
    master_status()
    display()


SetEventTarget("OnMasterInfoChange", OnMasterInfoChange)


		
		
		
		
