def __init__(self, time_per_duration): self.time_per_duration = time_per_duration self.synth = fluidsynth.Synth(1) self.synth.start(driver="alsa") # soundFont = synth.sfload("/home/pi/Documents/ChoriumRevA.SF2") soundFont = self.synth.sfload( "/home/pi/music_pro/arachno-soundfont-10-sf2/Arachno SoundFont - Version 1.0.sf2" ) # 设置乐器的channel,最后两个参数是bank和preset数 self.synth.program_select(1, soundFont, 0, 0) #Grand piano self.synth.program_select(2, soundFont, 0, 41) #Violin self.synth.program_select(3, soundFont, 0, 42) #Cello self.synth.program_select(4, soundFont, 0, 46) #Orchestral Harp self.synth.program_select(5, soundFont, 0, 56) #Trumpet self.synth.program_select(6, soundFont, 0, 32) #Acoustic Bass self.synth.program_select(7, soundFont, 0, 10) #Music Box self.synth.program_select(8, soundFont, 0, 16) #DrawBar Organ self.synth.program_select(9, soundFont, 0, 24) #Nylon Guitar #self.synth.program_select(10, soundFont, 0, 54) #Synth Voice #self.synth.program_select(11, soundFont, 0, 52) #Choir Aahs #self.synth.program_select(12, soundFont, 0, 48) #Strings Ensemble 1 #self.synth.program_select(13, soundFont, 0, 55) #Orchestra Hit self.channels_num = 9 self.onNotes = []
def load_soundfont(soundfont): try: fs = pyfluidsynth.Synth() fluid = fs.sfload(soundfont) if fluid: print("音源加载成功") except: fs = None fluid = -1 print("音源加载失败") return fs, fluid
#!/usr/bin/env python3 # -*- coding: utf-8 -*- import os import sys import time this_dir = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(this_dir, '../..')) from mingus.midi import pyfluidsynth fs = pyfluidsynth.Synth() fs.start(driver="alsa") sfid = fs.sfload(os.path.join(this_dir, "example.sf2")) fs.program_select(0, sfid, 0, 0) fs.noteon(0, 60, 30) fs.noteon(0, 67, 30) fs.noteon(0, 76, 30) time.sleep(1.0) fs.noteoff(0, 60) fs.noteoff(0, 67) fs.noteoff(0, 76) time.sleep(1.0) fs.delete()
import time from sys import exit #midi player libraries from mingus.core import notes, chords from mingus.containers import * import mingus.midi.pyfluidsynth as fluidsynth # import RPi.GPIO as GPIO #for GPIO switch synth = fluidsynth.Synth(1) synth.start(driver="alsa") # soundFont = synth.sfload("/home/pi/Documents/ChoriumRevA.SF2") soundFont = synth.sfload("arachno-soundfont-10-sf2/Arachno SoundFont - Version 1.0.sf2") #assign instruments to separate channel numbers (1 is hammond organ, 2 is steel guitar, etc...) #program_select arguments: channel, soundFont, bank, preset synth.program_select(1, soundFont, 0, 16) #16 hammond organ synth.program_select(2, soundFont, 0, 26) #26 steel guitar synth.program_select(3, soundFont, 128, 0) #0 Bank 128 standard drums synth.program_select(4, soundFont, 0, 114) #114 steel drums synth.program_select(5, soundFont, 128, 48) #48 bank 128 orchestra drum kit synth.program_select(6, soundFont, 128, 25) #25 bank 128 TR-808 drum kit synth.program_select(7, soundFont, 0, 102) #102 echo drops synth.program_select(8, soundFont, 0, 11) #11 vibraphone synth.program_select(9, soundFont, 0, 13) #13 xylophone synth.program_select(10, soundFont, 0, 55) #55 orchestra hit synth.program_select(11, soundFont, 0, 86) #86 5th saw wave synth.program_select(12, soundFont, 0, 88) #88 fantasia #instrument numbers: https://www.midi.org/specifications/item/gm-level-1-sound-set
def __init__(self, music=None, fs=None, fluid=-1): self._init(music, fs, fluid) if self.fs is None: self.fs = pyfluidsynth.Synth() self.fluid = self.fs.sfload("soundfont/Hubbe64MB.sf2") self.fs.start()
# ---------- # ---------- # Output result if enabled: if out_sound or out_wav != "": from time import sleep import numpy as np if out_wav: import wave import pyaudio p = pyaudio.PyAudio() sr = 44100 samples = [] if sf2 != "": from mingus.midi import pyfluidsynth fs = pyfluidsynth.Synth(samplerate=sr) fsf2 = fs.sfload(sf2) fs.program_select(0, fsf2, 0, 0) for index, lrep_code in enumerate(notes): for index1, lrep_code1 in enumerate(lrep_code): for index2, lrep_code2 in enumerate(lrep_code1): for index3, lrep_code3 in enumerate(lrep_code2): if lrep_code3[0] != -1: fs.noteon(0, lrep_code3[0], volume * 100) samples.append( pyfluidsynth.raw_audio_string( np.array( fs.get_samples( int((sr * lrep_code3[1] * (60 / bpm)) / speed_multiplier))))) if lrep_code3[0] != -1:
def init(self): self.fs = fs.Synth()
scale_number = 1 last_scale_number = 1 clkLastState = 1 dtLastState = 1 scale_name = "" backtrack_number = 0 volume = 75 Noteid = '' endpoint = '/api/v1' duration = '' current_track = 0 may_rotate = True leadinstr = 1 backinginstr = 1 fs = pyfluidsynth.Synth(gain=2) fs.start(driver="alsa") sfid = fs.sfload("/usr/share/sounds/sf2/FluidR3_GM.sf2") fs.program_select(0, sfid, 0, 0) fs.program_change(2, 1) fs.program_change(1, 1) fs.program_change(3, 123) fs.program_change(9, 48) lcd = LCD.Lcd(E=23, RS=24, SDA=12, SCL=25) ips = check_output(['hostname', '--all-ip-addresses']).decode("utf-8") ip = ips.split(" ") print(ip[1]) lcd.clear_display() LockRotary = threading.Lock()