1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 |
- import types
- import time
-
- class ChordTester:
- def __init__( self, cfg, api ):
- self.api = api
- self.cfg = types.SimpleNamespace(**cfg.ChordTester)
-
- self.nextMs = 0
- self.isStartedFl = False
- self.curNoteCnt = 0
- self.curRepeatCnt = 0
- self.isPlayingFl = False
-
-
- def start( self ):
- self.api.set_hold_duty_all( self.cfg.holdDuty )
- if self.cfg.useVelTableFl:
- self.api.set_vel_table_all( self.cfg.pitchL )
- self.curNoteCnt = 0
- self.curRepeatCnt = 0
- self.isStartedFl = True
-
- def stop( self ):
- self.isStartedFl = False
- self.api.all_notes_off()
-
-
-
- def tick( self, ms ):
-
- if self.isStartedFl and ms >= self.nextMs:
-
- if self.isPlayingFl:
-
- # turn notes off
- for i in range(0,self.curNoteCnt+1):
- self.api.note_off( self.cfg.pitchL[i])
- time.sleep( 0.01 )
-
- # repeat or advance the chord note count
- self.curRepeatCnt += 1
- if self.curRepeatCnt >= self.cfg.repeatCnt:
- self.curRepeatCnt = 0
- self.curNoteCnt += 1
- if self.curNoteCnt >= len(self.cfg.pitchL):
- self.isStartedFl = False
- self.curNoteCnt = 0
-
- self.isPlayingFl = False
- self.nextMs = ms + self.cfg.pauseMs
-
- else:
- for i in range(0,self.curNoteCnt+1):
- if self.cfg.useVelTableFl:
- self.api.note_on_vel(self.cfg.pitchL[i], 45 )
- else:
- self.api.note_on_us(self.cfg.pitchL[i], self.cfg.atkUsec)
- time.sleep( 0.02 )
-
- self.nextMs = ms + self.cfg.durMs
- self.isPlayingFl = True
-
-
-
-
-
-
|