Package control :: Module theTime :: Class TheTime
[hide private]
[frames] | no frames]

Class TheTime

source code

        object --+        
                 |        
threading._Verbose --+    
                     |    
      threading.Thread --+
                         |
                        TheTime
Known Subclasses:
theTime2.TheTime2

The class containing timer and timed queue methods.

Automation is executed via a queue of events to be executed in time, format for the queue is a list of events, with each event represented as a list with the following format: [type, time, data]. The type field is a string, to be parsed in eventCaller.parseEvents(). Time is in beats and may be fractional. The data field may contain several parameters (not as sublist).

Instance Methods [hide private]
  __init__(self, eventCaller, bpm=60)
The class constructor.
  run(self)
The main clock increment method, also polling the event queue.
  startStopClock(self, state, offset=1)
Start or stop (pause) the clock.
  getCurrentBeat(self)
Get the current beat count.
  getQueue(self)
Get the contents of the timed queue.
  removeEvent(self, event)
Remove an event from the timed queue.
  removeEvent2(self, event)
Helper method for removeEvent, thread safe handling of the timed queue list.
  checkQueue(self, beat)
Check if any events in the queue are due for execution.
  insertQueue(self, timeStamp, event)
Insert an event into the queue, keeping the timeStamps in sorted order.
  insertQueue2(self, timeAndEvent)
Helper method for insertQueue, threadsafe queue access.
  insertQueueWithOffset(self, timeStamp, event)
Insert an event into the queue, keeping the timeStamps in sorted order.
  insertQueueWithOffset2(self, timeAndEvent)
Helper method for insertQueueWithOffset, threadsafe queue access.
  insertListFromNow(self, list)
Insert a list of timed events into the queue, transposing each event's timestamp relative to the "now" time.
  setBpm(self, bpm)
Set the clock tempo in beats per minute.
  stop(self)
Stops the thread from running, by setting isRunning = False.

Inherited from threading.Thread: __repr__, getName, isAlive, isDaemon, join, setDaemon, setName, start

Inherited from threading.Thread (private): _set_daemon

Inherited from threading._Verbose (private): _note

Inherited from object: __delattr__, __getattribute__, __hash__, __new__, __reduce__, __reduce_ex__, __setattr__, __str__


Instance Variables [hide private]
  queueMutex
The mutex for thread safe handling of the queue list.
  isRunning
Flag to keep the clock thread running, set to False to exit thread.
  timeResolution
Timer resolution in seconds, 0.001=millisecond resolution (not accurate).
  queue
The list of events in the timed queue.
  beatCounter
Counter for quarter notes at a given bpm.
  fractionalBeat
Counter for fractions of a beat.
  bpm
The tempo in beats per minute for the beat counter.
  runClock
Flag to run or pause the clock.

Properties [hide private]

Inherited from object: __class__


Method Details [hide private]

__init__(self, eventCaller, bpm=60)
(Constructor)

source code 

The class constructor.

Under normal operation this timer instance is a standard seconds and minutes clock so the bpm should not be changed.
Parameters:
  • self - The object pointer.
  • eventCaller - A pointer to the eventCaller object.
  • bpm - The beats per minute for the beat counter. Default = 60, this should not be modified in normal cicumstances.
Overrides: threading.Thread.__init__

run(self)

source code 
The main clock increment method, also polling the event queue.
Parameters:
  • self - The object pointer.
Overrides: threading.Thread.run

startStopClock(self, state, offset=1)

source code 

Start or stop (pause) the clock.

An optional offset may increment the current beat count when starting the clock.
Parameters:
  • self - The object pointer.
  • state - The running state (True or False) of the clock.
  • offset - The beat offset to be used for incrementing the beat counter when starting the clock.

getCurrentBeat(self)

source code 
Get the current beat count.
Parameters:
  • self - The object pointer.
Returns:
beatCount: The current beat count.

getQueue(self)

source code 
Get the contents of the timed queue.
Parameters:
  • self - The object pointer.
Returns:
The list of events in the timed queue.

removeEvent(self, event)

source code 
Remove an event from the timed queue.
Parameters:
  • self - The object pointer.
  • event - The event to be removed.

removeEvent2(self, event)

source code 
Helper method for removeEvent, thread safe handling of the timed queue list.
Parameters:
  • self - The object pointer.
  • event - The event to be removed.

checkQueue(self, beat)

source code 

Check if any events in the queue are due for execution.

Execute any events with timestamp <= timeNow. Times are in beats and so will be relative to the current tempo in bpm, timeNow is a beat counter, and the beat counter may be fractional.
Parameters:
  • self - The object pointer.
  • beat - The beat count (including any fractional part) used as "now" for dispersing timed events in the queue.

insertQueue(self, timeStamp, event)

source code 
Insert an event into the queue, keeping the timeStamps in sorted order.
Parameters:
  • self - The object pointer.
  • timeStamp - The time to insert the event at.
  • event - The event to insert.

insertQueue2(self, timeAndEvent)

source code 
Helper method for insertQueue, threadsafe queue access.
Parameters:
  • self - The object pointer.
  • timeAndEvent - A list of [timeStamp, event] for insertion into the queue.

insertQueueWithOffset(self, timeStamp, event)

source code 
Insert an event into the queue, keeping the timeStamps in sorted order. The time for the event is offset with the current beat time, so e.g. a time of 1 will be executed one beat into the future.
Parameters:
  • self - The object pointer.
  • timeStamp - The time to insert the event at.
  • event - The event to insert.

insertQueueWithOffset2(self, timeAndEvent)

source code 
Helper method for insertQueueWithOffset, threadsafe queue access.
Parameters:
  • self - The object pointer.
  • timeAndEvent - A list of [timeStamp, event] for insertion into the queue.

insertListFromNow(self, list)

source code 
Insert a list of timed events into the queue, transposing each event's timestamp relative to the "now" time.
Parameters:
  • self - The object pointer.
  • list - The list of events to be inserted.

setBpm(self, bpm)

source code 
Set the clock tempo in beats per minute.
Parameters:
  • self - The object pointer.

stop(self)

source code 
Stops the thread from running, by setting isRunning = False.
Parameters:
  • self - The object pointer.

Instance Variable Details [hide private]

queueMutex

The mutex for thread safe handling of the queue list.

isRunning

Flag to keep the clock thread running, set to False to exit thread.

timeResolution

Timer resolution in seconds, 0.001=millisecond resolution (not accurate).

queue

The list of events in the timed queue.

beatCounter

Counter for quarter notes at a given bpm.

fractionalBeat

Counter for fractions of a beat.

bpm

The tempo in beats per minute for the beat counter.

runClock

Flag to run or pause the clock.