当前位置: 首页>>代码示例>>Python>>正文


Python Note.freq方法代码示例

本文整理汇总了Python中note.Note.freq方法的典型用法代码示例。如果您正苦于以下问题:Python Note.freq方法的具体用法?Python Note.freq怎么用?Python Note.freq使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在note.Note的用法示例。


在下文中一共展示了Note.freq方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SFM

# 需要导入模块: from note import Note [as 别名]
# 或者: from note.Note import freq [as 别名]
class SFM(object):

  # pitch registers
  transpositionSemitones = 0
  octaveNumber = 3

  # tempo registers
  tempo = 60
  currentBeatValue = 60.0/tempo
  currentBeat = 0
  totalDuration = 0.0
  
  # dynamics registers
  crescendoSpeed = 1.1
  currentCrescendoSpeed = crescendoSpeed
  crescendoBeatsRemaining = 0.0
  maximumAmplitude = 0.0

  # tuple registers
  duration = 60.0/tempo
  amplitude = 1.0
  decay = 1.0
  
  # I/O
  input = ""
  
  #########################################################
  
  # initialize Note, Rhythm, and Dynamics objects
  def __init__(self, SCALE):
    NOTES, FREQ_DICT = SCALE
    self.note = Note(NOTES, FREQ_DICT)
    self.rhythm = Rhythm()
    self.dynamics = Dynamics()
    self.equalizerFactor = { }
    self.equalizerFactor[-0.1] = 1.0
    self.equalizerFactor[220] = 1.0
    self.equalizerFactor[440] = 0.7
    self.equalizerFactor[880] = 0.35
    self.equalizerFactor[1760] = 0.15
    self.equalizerFactor[3520] = 0.15
    self.equalizerFactor[7040] = 0.15
    self.equalizerFactor[14080] = 0.15
    self.equalizerFactor[28160] = 0.15
    self.equalizerFactor[56320] = 0.15
    self.equalizerBreakPoints = [-0.1, 220, 440, 880, 1760, 3520, 7040, 14080, 28160, 56320]
    
    # self.tempo = 60
    # self.currentBeatValue = 60.0/self.tempo
    # self.octaveNumber = 3
    
  def equalize(self, freq):
    a, b = interval(freq, self.equalizerBreakPoints)
    f = mapInterval(freq, a,b, self.equalizerFactor[a], self.equalizerFactor[b])
    # print freq, a, b, f
    return f

  # return tuple as string given frequency,
  # duration, decay, and amplitude
  def _tuple(self, freq, duration):
    output = `freq`
    output += " "+`duration`
    a = self.amplitude
    a = a*self.equalize(freq)
    output += " "+`a`
    output += " "+`self.decay`
    return output
  
  # return tuple as string from frequency of token
  # and root and suffix of token
  def tuple(self, freq, root, suffix):
    if suffix.find(",") > -1:
          thisDuration = self.duration*(1 - self.rhythm.breath)
          output = self._tuple(freq, thisDuration)
          output += "\n"
          output += self._tuple(0, self.duration - thisDuration)
    else:
          output = self._tuple(freq, self.duration)
    return output
   
  def updateRhythm(self, cmd):
    self.currentBeatValue, self.duration = self.rhythm.value(cmd, self)

  def emitNote(self, token):
	if self.crescendoBeatsRemaining > 0:
	  self.amplitude = self.amplitude*self.currentCrescendoSpeed
	  self.crescendoBeatsRemaining -= self.currentBeatValue
	freq, root, suffix = self.note.freq(token, self.transpositionSemitones, self.octaveNumber)
	self.output += self.tuple(freq, root, suffix) + "\n"
	
	# summary data
	self.totalDuration += self.duration
	self.currentBeat += self.currentBeatValue
	if self.amplitude > self.maximumAmplitude:
	  self.maximumAmplitude = self.amplitude

  def executeCommand(self, ops): 
  
  	cmd = ops[0]
  	
#.........这里部分代码省略.........
开发者ID:jxxcarlson,项目名称:sf2sound,代码行数:103,代码来源:SFM.py


注:本文中的note.Note.freq方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。