本文整理汇总了Python中mingus.midi.fluidsynth.init函数的典型用法代码示例。如果您正苦于以下问题:Python init函数的具体用法?Python init怎么用?Python init使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了init函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, packetlistener):
self._packetlistener = packetlistener
self._packetanalyser = PacketAnalyser(self._packetlistener)
fluidsynth.init("Bandpass.sf2", 'alsa')
self._music_loop()
示例2: main
def main():
if not os.path.isfile('./data/probs.json'):
print ('Creating json file...')
fname = "./data/interval-5gram.csv"
counts = get_counts(fname, 4)
probs = get_probs(counts)
with open('./data/probs.json', 'w') as outfile:
json.dump(probs, outfile)
with open('./data/probs.json', 'r') as infile:
probs_dict = json.load(infile, encoding='utf-8')
start_int = C4
melody = []
fluidsynth.init("/usr/share/sounds/sf2/FluidR3_GM.sf2", "alsa")
streamer = stream_notes(probs_dict)
for i in range(100):
next_int = start_int + int(next(streamer))
next_note = Note()
next_note.from_int(next_int)
melody.append(next_note)
start_int = next_int
print(next_note)
fluidsynth.play_Note(next_note)
time.sleep(.2)
示例3: generate_composition
def generate_composition(pattern, progression_type, nb_bars, key="C", rythm=60):
fluidsynth.init("198_u20_Electric_Grand.SF2") # permet d'initialiser l'instrument
newComposition = Composition()
progression_list = on_progression_type_change(progression_type, nb_bars)
left_hand = generate_pattern(progression_list, key, pattern, nb_bars)
newComposition.add_track(left_hand)
MidiFileOut.write_Composition("myComposition.mid", newComposition, rythm, False)
示例4: __init__
def __init__(self, master):
frame = Frame(master)
frame.pack()
fluidsynth.init("ChoriumRevA.SF2")
roman_num = [0,2,4,5,7,9,11]
self.progression = []
self.buttons = {}
self.prog_var = StringVar()
self.display = Label( master, textvariable = self.prog_var).pack()
self.uniprog_var = StringVar()
self.unidisplay = Label( master, textvariable = self.uniprog_var).pack()
self.sug_var = StringVar()
self.sug_label = Label( master, textvariable = self.sug_var).pack()
#### Chord Buttons ####
self.key_btn = Listbox(frame)
self.key_btn.bind("<<ListboxSelect>>", self.display_progression)
self.key_btn.pack(side=BOTTOM)
for k in number.keys():
self.key_btn.insert(END, k)
for ch in roman_num:
btn = Button(frame, text=roman[ch], command=partial( self.print_ch, ch ) )
btn.pack(side=LEFT)
self.buttons[ ch ] = btn
#### other buttons ####
self.pop = Button(frame, text='Del', command=self.pop_ch)
self.pop.pack(side=BOTTOM)
self.play = Button(frame, text='Play', command=self.play_prog)
self.play.pack(side=TOP)
self.sugg = Button(frame, text='?', command=self.suggest)
self.sugg.pack(side=BOTTOM)
self.save_btn = Button(frame, text='Save', command=self.save_midi)
self.save_btn.pack(side=TOP)
#### Checkbox buttons for intervals ####
self.add7_var = BooleanVar()
self.add7 = Checkbutton( master, text="+ 7", variable = self.add7_var )
self.add7.pack()
self.maj_var = BooleanVar()
self.maj = Checkbutton( master, text="Major", variable = self.maj_var )
self.maj.pack()
示例5: playNotes
def playNotes(notes, xscale = 0.01):
fluidsynth.init('/usr/share/sounds/sf2/FluidR3_GM.sf2',"alsa")
currTime = 0
for n in notes:
waitTime = n.startx * xscale - currTime
currTime = n.startx * xscale
fluidsynth.play_Note(pow(n.energy, 0.2), 0, 100)
print("Played %s, Waiting for %s " % (n, waitTime))
time.sleep(waitTime)
fluidsynth.stop_everything()
示例6: __init__
def __init__(self):
self.store = db()
fluidsynth.init(MIDI_FILE, 'alsa')
self.builder = gtk.Builder()
self.builder.add_from_file('res/gui.glade')
self.window = self.builder.get_object('window')
self.new_evolution_dialog = self.builder.get_object('new_evolution_dialog')
self.new_neural_network_dialog = self.builder.get_object('new_neural_network_dialog')
self.open_evolution_dialog = self.builder.get_object('open_evolution_dialog')
self.nn_list = gtk.ListStore(str)
self.nn_combo = self.builder.get_object('nn_combo')
self.nn_combo.set_model(self.nn_list)
cell = gtk.CellRendererText()
self.nn_combo.pack_start(cell, True)
self.nn_combo.add_attribute(cell,'text', 0)
self.update_nn_list()
self.evolution_list = gtk.ListStore(str)
self.evolution_combo = self.builder.get_object('evolution_combo')
self.evolution_combo.set_model(self.evolution_list)
cell = gtk.CellRendererText()
self.evolution_combo.pack_start(cell, True)
self.evolution_combo.add_attribute(cell, 'text', 0)
self.update_evolution_list()
self.genome_list = gtk.ListStore(int, str)
self.genome_view = self.builder.get_object('genome_view')
self.genome_view.set_model(self.genome_list)
cell = gtk.CellRendererText()
column = gtk.TreeViewColumn('Genome', cell, text=1)
self.genome_view.append_column(column)
self.controls = {
'initialize': self.builder.get_object('initialize_button'),
'evaluate': self.builder.get_object('evaluate_button'),
'select' : self.builder.get_object('apply_selection_button'),
'play' : self.builder.get_object('play_button')
}
self.console = gtk.TextBuffer()
self.builder.get_object('console').set_buffer(self.console)
# hide dialogs instead of destroying them for reuse
self.hide_dialog = gtk.Widget.hide_on_delete
self.builder.connect_signals(self)
示例7: play_pattern
def play_pattern(pattern_index, key):
pattern = patterns.PATTERNS[pattern_index]
fluidsynth.init("198_u20_Electric_Grand.SF2") # permet d'initialiser l'instrument
previews_note = None
b = Bar(key, (4, 4))
position_note = 0
already_used=[]
for pattern_note in pattern :
if position_note not in already_used :
is_chord = chord_length(pattern_note, pattern, position_note)
if is_chord[2] :
note_list = []
# c est un accord
for p_note in pattern[is_chord[0]:is_chord[1]+1] :
note_str = get_note_pattern(p_note, key)
note = Note(note_str, p_note[5])
if previews_note is not None:
if p_note[4]=='+':
if int(note) < previews_note :
note.octave_up()
elif p_note[4]=='-':
if int(note) > previews_note :
note.octave_down()
previews_note = int(note)
note_list.append(note)
for n in range(is_chord[0], is_chord[1]+1):
already_used.append(n)
b.place_notes(note_list, pattern_note[1])
else :
note_str = get_note_pattern(pattern_note, key)
note = Note(note_str, pattern_note[5])
if previews_note is not None:
if pattern_note[4]=='+':
if int(note) < previews_note :
note.octave_up()
elif pattern_note[4]=='-':
if int(note) > previews_note :
note.octave_down()
previews_note = int(note)
b.place_notes(note, pattern_note[1])
already_used.append(position_note)
position_note+=1
fluidsynth.play_Bar(b, 1, 60)
示例8: __init__
def __init__(self, instrument=None):
super(FlowTrack, self).__init__(instrument)
if type(instrument) is Guitar:
fluidsynth.init('soundfonts/acoustic_guitar.sf2')
else:
fluidsynth.init('soundfonts/grand_piano.sf2')
self.rate = 100
self.chords = []
self.key = 'C'
self.octave = 4
示例9: build
def build(self):
fluidsynth.init(os.path.join(ROOT_DIR, 'sounds', 'FluidR3_GM.sf2'))
self.midi_in = MidiInputDispatcher()
midi_device = self.config.get('MIDI', 'Input device')
if midi_device:
self.midi_in.open_port(midi_device)
self.setting_panel = Settings()
party = PlayerParty()
sm = TonePoemGame(OrderedDict([
('area', AreaScreen(name='area')),
('encounter', EncounterScreen(name='encounter', party=party))
]), app=self)
return sm
示例10: __init__
def __init__(self, filename):
fluidsynth.init(filename)
note_names = ("C-4", "C#4", "D-4", "D#4", "E-4", "F-4", "F#4", "G-4", "G#4", "A-4", "A#4", "B-4",
"C-5", "C#5", "D-5", "D#5", "E-5", "F-5", "F#5", "G-5", "G#5", "A-5", "A#5", "B-5")
coords = (15, 35, 52, 71, 88, 125, 144, 160, 180, 197, 216, 234,
270, 289, 307, 325, 343, 378, 398, 415, 434, 452, 470, 487)
self.is_pressed = dict.fromkeys(note_names, [False] * len(note_names))
self.note_coordinate = dict(zip(note_names, coords))
self.note_names = note_names
self.window_title = 'Keyboard'
cv2.namedWindow(self.window_title)
self.img = cv2.imread('./resources/keyboard.jpg', cv2.CV_LOAD_IMAGE_COLOR)
cv2.imshow(self.window_title, self.img)
self.turn_sound_on()
示例11: __init__
def __init__(self, soundfont_name=None):
if soundfont_name is None:
fluidsynth.init('../soundfonts/soundfont.sf2', 'alsa')
else:
fluidsynth.init(soundfont_name, 'alsa')
self.m_chain = MarkovChain(get_all_progressions())
self.sim = self.m_chain.infinite_progression()
down1 = (0.7, 0.05, 0.2)
down2 = (0.2, 0.05, 0.7)
off = (0.0, 0.4, 0.1)
self.bassproba = [down1, off, down2, off, down1, off, down2, off]
self.current = self.m_chain.START
示例12: __init__
def __init__(self,
soundfont_file,
soundfont_driver="alsa",
valve_mapping=default_valve_mapping,
freq_ranges=default_freq_ranges,
note_mapping=default_note_mapping):
"""
Initialize Trumpet
"""
self.valve_mapping = valve_mapping # Valve to key map
self.freq_ranges = freq_ranges # Freq range to harmonic series
# Note mapping indexed as [freq range index][valve combo (index)]
self.note_mapping = note_mapping
# Initialize Fluidsynth
self.soundfont_file = soundfont_file
self.soundfont_driver = soundfont_driver
fluidsynth.init(soundfont_file, soundfont_driver)
# Keep track of the current note state
self.current_note = ""
self.prev_freq = 0
示例13: generate_composition
def generate_composition(pattern_index, progression_type, nb_bars, mode='none', key="C", rythm=60):
fluidsynth.init("198_u20_Electric_Grand.SF2") # permet d'initialiser l'instrument
newComposition = Composition()
progression_list = on_progression_type_change(progression_type, nb_bars)
# truc pour la main droite
if nb_bars == 1 :
phrase_list = choose_phrases(key, mode, nb_bars)
right_hand = use_phrase(phrase_list, progression_list, nb_bars, pattern_index, mode='none', key="C")
else :
chorus = generate_chorus(progression_list, pattern_index, mode, key)
#chorus retourne : une phrase de debut, une phrase de fin, 3 bars fixes
phrase_list = choose_first_phrases(nb_bars, key, mode, chorus[1], chorus[2], pattern_index)
right_hand = generate_long_right_hand(phrase_list, progression_list, nb_bars, pattern_index, mode, key, chorus)
newComposition.add_track(right_hand)
left_hand = generate_pattern(progression_list, key, pattern_index, nb_bars)
newComposition.add_track(left_hand)
MidiFileOut.write_Composition("myCompo.mid", newComposition, rythm, False)
return newComposition
示例14: playProgression
def playProgression():
progression = ["I", "vi", "ii", "iii7", "I7", "viidom7", "iii7", "V7"]
key = "C"
chords = progressions.to_chords(progression, key)
if not fluidsynth.init(SF2):
print "Couldn't load soundfont", SF2
sys.exit(1)
while 1:
i = 0
for chord in chords:
c = NoteContainer(chords[i])
l = Note(c[0].name)
p = c[1]
l.octave_down()
print ch.determine(chords[i])[0]
# Play chord and lowered first note
fluidsynth.play_NoteContainer(c)
fluidsynth.play_Note(l)
time.sleep(1.0)
# Play highest note in chord
fluidsynth.play_Note(c[-1])
# 50% chance on a bass note
if random() > 0.5:
p = Note(c[1].name)
p.octave_down()
fluidsynth.play_Note(p)
time.sleep(0.50)
# 50% chance on a ninth
if random() > 0.5:
l = Note(intervals.second(c[0].name, key))
l.octave_up()
fluidsynth.play_Note(l)
time.sleep(0.25)
# 50% chance on the second highest note
if random() > 0.5:
fluidsynth.play_Note(c[-2])
time.sleep(0.25)
fluidsynth.stop_NoteContainer(c)
fluidsynth.stop_Note(l)
fluidsynth.stop_Note(p)
i += 1
print "-" * 20
示例15: synthComm
def synthComm():
# print "I AM IN synthComm"
timeStart = time.time()
fluidsynth.init(config.sf2Path)
note = Note()
ser = serial.Serial(config.megaPath, config.megaBaud,timeout = 1)
fluidsynth.stop_Note(note)
while config.playing:
info = ser.readline()
print info
if info is not '' and len(info) == 9:
# print info
# print timeStart
fluidsynth.stop_Note(note)
# print "---"
# print len(info)
# print "---"
timeElp, x, y, vel = parseInput(timeStart, info)
n = pos2Num(x,y)
# print n
# print names[n]
note = Note(names[n],octave)
note.velocity = vel
fluidsynth.play_Note(note)
print "-----"
print "Time: {0} \nPosition: {1},{2}\n Velocity: {3}".format(timeElp, x, y, vel)
print "-----"
else:
fluidsynth.stop_Note(note)
# config.userHits = np.hstack((config.userHits, np.array([[time],[vel],[x],[y])))
# when done, close out connection
ser.close()
# print " I HAVE CLOSED THE connection"
return