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


Python Timeline.render方法代码示例

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


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

示例1: playchords

# 需要导入模块: from timeline import Timeline [as 别名]
# 或者: from timeline.Timeline import render [as 别名]
def playchords(imu):
    
    key = Note('E3')
    scale = Scale(key, 'harmonic minor')
    progression = Chord.progression(scale, base_octave=key.octave)
    time = 0.0
    timeline = Timeline()    
    chord = progression[0]
    
    d = 3.0 #length of time (seconds)
    chords = [Hit(chord.notes[0], d), Hit(chord.notes[1], d), Hit(chord.notes[2], d), Hit(chord.notes[0], d)]
        
    amp = 0.25 #Amplitude
    thrd = None
    
    while True: 
        timeline = Timeline()
        acc = imu.getacc()
        #print "acc is {}".format(acc)
        
        ax, ay, az = acc
        if ax > 1.5:
            timeline.add(0.0, chords[0])
        elif ax < -1.5:
            timeline.add(0.0, chords[1])
        if ay > 1.5:
            timeline.add(0.0, chords[2])
        elif ay < -1.5:
            timeline.add(0.0, chords[3])
    
        data = timeline.render() * amp
        
        if thrd == None or not thrd.isAlive():
            thrd = threading.Thread(target=play, args=(data,))
            thrd.start()
开发者ID:spandanb,项目名称:gyroMusic,代码行数:37,代码来源:musickeyer.py

示例2: singlebeat

# 需要导入模块: from timeline import Timeline [as 别名]
# 或者: from timeline.Timeline import render [as 别名]
def singlebeat(beat, *args, **kwargs):
    beat_timeline = Timeline()
    time = 0.0
    beat_timeline.add(time+0.0, beat)

    print "Rendering beat audio..."
    beat_data = beat_timeline.render()

    return beat_data
开发者ID:Slater-Victoroff,项目名称:BerkleeMusicHack,代码行数:11,代码来源:sounds.py

示例3: singlenote

# 需要导入模块: from timeline import Timeline [as 别名]
# 或者: from timeline.Timeline import render [as 别名]
def singlenote(note_number, *args, **kwargs):
    singlenote_timeline = Timeline()
    time = 0.0 # Keep track of currect note placement time in seconds

    # Strum out root chord to finish
    chord = kwargs['progression'][0]
    singlenote_timeline.add(time + 0.0, Hit(chord.notes[note_number], 3.0))

    print "Rendering singlenote audio..."
    singlenote_data = singlenote_timeline.render()

    return singlenote_data
开发者ID:Slater-Victoroff,项目名称:BerkleeMusicHack,代码行数:14,代码来源:sounds.py

示例4: strum

# 需要导入模块: from timeline import Timeline [as 别名]
# 或者: from timeline.Timeline import render [as 别名]
def strum(*args, **kwargs):
    strum_timeline = Timeline()
    time = 0.0 # Keep track of currect note placement time in seconds

    # Strum out root chord to finish
    chord = kwargs['progression'][0]
    strum_timeline.add(time + 0.0, Hit(chord.notes[0], 4.0))
    strum_timeline.add(time + 0.1, Hit(chord.notes[1], 4.0))
    strum_timeline.add(time + 0.2, Hit(chord.notes[2], 4.0))
    strum_timeline.add(time + 0.3, Hit(chord.notes[1].transpose(12), 4.0))
    strum_timeline.add(time + 0.4, Hit(chord.notes[2].transpose(12), 4.0))
    strum_timeline.add(time + 0.5, Hit(chord.notes[0].transpose(12), 4.0))

    print "Rendering strum audio..."
    strum_data = strum_timeline.render()

    return strum_data
开发者ID:Slater-Victoroff,项目名称:BerkleeMusicHack,代码行数:19,代码来源:sounds.py

示例5: arpeggio

# 需要导入模块: from timeline import Timeline [as 别名]
# 或者: from timeline.Timeline import render [as 别名]
def arpeggio(*args, **kwargs):

    arpeggio_timeline = Timeline()
    time = 0.0 # Keep track of currect note placement time in seconds

    # Add progression to timeline by arpeggiating chords from the progression
    for index in [0, 1]:
      chord = kwargs['progression'][index]
      root, third, fifth = chord.notes
      arpeggio = [root, third, fifth, third, root, third, fifth, third]
      for i, interval in enumerate(arpeggio):
        ts = float(i * 2) / len(arpeggio)
        arpeggio_timeline.add(time + ts, Hit(interval, 1.0))
      time += 2.0

    print "Rendering arpeggio audio..."
    arpeggio_data = arpeggio_timeline.render()

    return arpeggio_data
开发者ID:Slater-Victoroff,项目名称:BerkleeMusicHack,代码行数:21,代码来源:sounds.py

示例6: enumerate

# 需要导入模块: from timeline import Timeline [as 别名]
# 或者: from timeline.Timeline import render [as 别名]
for index in [0, 2, 3, 1,    0, 2, 3, 4,    5, 4, 0]:
  chord = progression[index]
  root, third, fifth = chord.notes
  arpeggio = [root, third, fifth, third, root, third, fifth, third]
  for i, interval in enumerate(arpeggio):
    ts = float(i * 2) / len(arpeggio)
    timeline.add(time + ts, Hit(interval, 1.0))
  time += 2.0

# Strum out root chord to finish
chord = progression[0]
timeline.add(time + 0.0, Hit(chord.notes[0], 4.0))
timeline.add(time + 0.1, Hit(chord.notes[1], 4.0))
timeline.add(time + 0.2, Hit(chord.notes[2], 4.0))
timeline.add(time + 0.3, Hit(chord.notes[1].transpose(12), 4.0))
timeline.add(time + 0.4, Hit(chord.notes[2].transpose(12), 4.0))
timeline.add(time + 0.5, Hit(chord.notes[0].transpose(12), 4.0))

print "Rendering audio..."

data = timeline.render()

# Reduce volume to 25%
data = data * 0.25

print "Playing audio..."

playback.play(data)

print "Done!"
开发者ID:ShPavel,项目名称:python-musical,代码行数:32,代码来源:example-01.py

示例7: main

# 需要导入模块: from timeline import Timeline [as 别名]
# 或者: from timeline.Timeline import render [as 别名]

#.........这里部分代码省略.........
    dice_roll = random.choice([1,2,3,4,5])
  else:
    dice_roll = random.choice([1,2,3,4,5,6])

  if (dice_roll < 5 and _debug <> 1):
    print "Going back to sleep"
    sys.exit()

  # We're alive, import what else we need now
  sys.path.append(os.path.join(os.path.dirname(__file__), 'python-musical'))

  from musical.theory import Note, Scale, Chord
  from musical.audio import effect, playback

  from timeline import Hit, Timeline

  # Define key and scale
  key = Note((random.choice(Note.NOTES), random.choice([2,3,3])))

  scales = ['major', 'minor', 'melodicminor', 'harmonicminor', 'pentatonicmajor', 'bluesmajor', 'pentatonicminor', 'bluesminor', 'augmented', 'diminished', 'wholehalf', 'halfwhole', 'augmentedfifth', 'japanese', 'oriental', 'ionian', 'phrygian', 'lydian', 'mixolydian', 'aeolian', 'locrian']
  scale = Scale(key, random.choice(scales))

  print key
  print scale

  # Grab progression chords from scale starting at the octave of our key
  progression = Chord.progression(scale, base_octave=key.octave)

  time = 0.0 # Keep track of currect note placement time in seconds

  timeline = Timeline()

  # Pick a notes from a chord randomly chosen from a list of notes in this progression
  chord = progression[ random.choice(range(len(progression)-1)) ]
  notes = chord.notes

  melodies = [
    [1.0, 0.1, 0.2, 0.1, 0.2, 0.10, 0.1],
    [0.8, 0.1, 0.1, 0.2],
    [0.8, 0.4, 0.1, 0.2, 0.4, 0.1, 0.2],
    [0.8, 0.4, 0.4, 0.2, 0.2, 0.1, 0.1],
    [0.4, 0.0, 0.1, 0.1, 0.2, 0, 0.1, 0.4],
    [0.1, 0.1, 0.1, 0.0, 0.2, 0.0, 0.1, 0.2, 0.4],
    [0.8, 0.4, 0.1, 0.4, 0.2, 0.2, 0.1, 0.2, 0.8, 0.1, 0.4, 0.1],
    [0.2, 0.2, 0.4, 0.2, 0.1, 0.1, 0.0, 0.2],
    [1.0, 0.1, 0.2, 0.1, 0.2, 0.2],
    [0.2, 0.1, 0.2, 0.4, 0.1, 0.2, 0.4],
    [0.4, 0.1, 0.4, 0.2, 0.4, 0.1, 0.4, 0.2],
    [0.1, 0.1, 0.1, 0.2, 0.1, 0.1, 0.2],
    [0.1, 0.1, 0.1, 0.2, 0.1, 0.1, 0.1, 0.2, 0.0],
    [0.1, 0.0, 0.1, 0.0, 0.1, 0.0, 0.2, 0.0, 0.2, 0.0, 0.1, 0.1, 0.3],
  ]

  random_melody = random.choice(melodies)
  print random_melody

  last_interval = 0.0
  last_transpose = 0

  for i, interval in enumerate(random_melody):
    random_note = random.choice(notes)

    # the first note should be high
    # identical intervals should often hold the same pitch
    # otherwise, pick a random pitch
    if i == 0:
      random_transpose = random.choice([8, 12])
    elif (last_interval == interval):
      if random.choice([0,1,2]) == 2:
        random_transpose = last_transpose
      else:
        random_transpose = 0
    else:
      random_transpose = random.choice([0, 2,4,6,8,10,12])

    last_interval = interval
    last_transpose = random_transpose

    note = random_note.transpose(random_transpose)
    #print note

    # favour queued notes, but occasionally overlap them too
    if (random.choice([1,2,3,4,5,6]) > 2):
      time = time + interval
      timeline.add(time, Hit(note, interval))
    else:
      timeline.add(time, Hit(note, interval))
      time = time + interval

  print "Rendering audio..."
  data = timeline.render()

  # Reduce volume to 95%
  data = data * 0.95

  print "Playing audio..."
  for i in range(random.choice([1,2])):
    playback.play(data)

  print "Done!"
开发者ID:suttree,项目名称:araduino,代码行数:104,代码来源:araduino.py


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