import  math
from timestamp import formatTimeStamp

class Metronome:
    bpm = 0
    volume = 0
    meter=1
    name=''
    play=''
    pmode =''
    startTs =0
    stopTs = 0
    ticks = 0

    def __init__(self, ticks, bpm, tStart, tStop, vol, pmode, name="default",play='mono', meter = 1):
        self.ticks = ticks
        self.bpm = bpm
        self.startTs = tStart
        self.stopTs = tStop
        self.volume = vol
        self.meter = meter
        self.pmode = pmode
        self.name = name
        self.play = play

    def doesTimeOverlap(self, other):
        if(self.startTs  < other.startTs):
            return self.stopTs >  other.startTs
        return  other.stopTs > self.startTs

    def generateStart(self):
        dt={}
        dt['ts'] = formatTimeStamp(self.startTs)
        dt['action']='start'
        dt['bpm'] = self.bpm
        dt['vol'] = self.volume
        dt['mode'] = self.pmode
        dt['name'] = self.name
        dt['meter'] = self.meter
        dt['sound'] = self.pmode
        dt['ticks'] = self.ticks
        return dt

    def generateStop(self):
        dt={}
        dt['ts'] = formatTimeStamp(self.stopTs)
        dt['action']='stop'
        dt['ticks'] = self.ticks
        return  dt

    def setMeter(self,meter):
        self.meter = meter

