picadae calibration programs
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ChordTester.py 2.0KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import types
  2. import time
  3. class ChordTester:
  4. def __init__( self, cfg, api ):
  5. self.api = api
  6. self.cfg = types.SimpleNamespace(**cfg.ChordTester)
  7. self.nextMs = 0
  8. self.isStartedFl = False
  9. self.curNoteCnt = 0
  10. self.curRepeatCnt = 0
  11. self.isPlayingFl = False
  12. def start( self ):
  13. self.api.set_hold_duty_all( self.cfg.holdDuty )
  14. if self.cfg.useVelTableFl:
  15. self.api.set_vel_table_all( self.cfg.pitchL )
  16. self.curNoteCnt = 0
  17. self.curRepeatCnt = 0
  18. self.isStartedFl = True
  19. def stop( self ):
  20. self.isStartedFl = False
  21. self.api.all_notes_off()
  22. def tick( self, ms ):
  23. if self.isStartedFl and ms >= self.nextMs:
  24. if self.isPlayingFl:
  25. # turn notes off
  26. for i in range(0,self.curNoteCnt+1):
  27. self.api.note_off( self.cfg.pitchL[i])
  28. time.sleep( 0.01 )
  29. # repeat or advance the chord note count
  30. self.curRepeatCnt += 1
  31. if self.curRepeatCnt >= self.cfg.repeatCnt:
  32. self.curRepeatCnt = 0
  33. self.curNoteCnt += 1
  34. if self.curNoteCnt >= len(self.cfg.pitchL):
  35. self.isStartedFl = False
  36. self.curNoteCnt = 0
  37. self.isPlayingFl = False
  38. self.nextMs = ms + self.cfg.pauseMs
  39. else:
  40. for i in range(0,self.curNoteCnt+1):
  41. if self.cfg.useVelTableFl:
  42. self.api.note_on_vel(self.cfg.pitchL[i], 45 )
  43. else:
  44. self.api.note_on_us(self.cfg.pitchL[i], self.cfg.atkUsec)
  45. time.sleep( 0.02 )
  46. self.nextMs = ms + self.cfg.durMs
  47. self.isPlayingFl = True