Exemple #1
0
def thread_NoteContainer(notes, duration, instr, *args):
    nc = NoteContainer(notes)
    if instr is not None:
        fluidsynth.set_instrument(nc[0].channel, instr)
    t = Thread(target=play_stop_NoteContainer, args=(nc, duration))
    t.start()
    return t
Exemple #2
0
    def play(self):
        fluidsynth.init('/usr/share/sounds/sf2/FluidR3_GM.sf2', 'alsa')
        fluidsynth.set_instrument(0, self.instrument)  # Use channel 0

        self.previous = int(SoundGen.kNoteNone)  # Previously played note

        self.shift = random.randint(-10, 5)  # Allow the key to be shifted

        beat_tracker = int(0)  # 4/4 time.
        while self.should_stop == False:
            v = random.randint(65, 75)
            if beat_tracker % 8 == 0:
                # First beat, strong
                v = random.randint(85, 95)
            elif (beat_tracker - 4) % 8 == 0:
                # Third beat, semi-strong
                v = random.randint(75, 85)
            elif beat_tracker % 2 == 1:
                # Off-beat, very soft
                v = random.randint(55, 65)

            # Random note length
            possible_lengths = [
                4
            ] + [2] * 10 + [1] * 4  # 4 is 2 beats, 2 is 1 beat, 1 is half-beat
            if beat_tracker % 2 == 1:  # avoid non-half-beat if currently in half-beat
                possible_lengths += [1] * 20  # Add weight to half-beat
            length = random.choice(possible_lengths)
            beat_tracker += length

            if self.previous != SoundGen.kNoteNone:
                fluidsynth.stop_Note(self.previous + self.shift, 0)
            self.previous = SoundGen.__next_note__(self.previous)
            fluidsynth.play_Note(self.previous + self.shift, 0, v)
            time.sleep(length * self.OneBeatLength)
Exemple #3
0
    def __init__(self):
        # possible fluidsynth guys
        ##main_volume(channel, value)
        ##modulation(channel, value)
        ##pan(channel, value)

        if not fluidsynth.init(
                os.path.join(config.RESOURCEdirectory, config.SOUNDfont),
                config.FLUIDSYNTHdriver):
            sys.exit(" COULD NOT LOAD SOUNDFONT PianoMenu.sf2 ")
        # set instruments on each channel.
        fluidsynth.set_instrument(
            config.PIANOchannel,  ## channel to set instrument on
            config.SOUNDfontPIANO)  ## instrument.  determined by sound font

        self.keysmod12 = [
            "C", "C#", "D", "Eb", "E", "F", "F#", "G", "Ab", "A", "Bb", "B"
        ]
        self.keyson = [0] * 12  # denotes all keys on in an octave
        self.newnotesonlist = [
        ]  # list of new [note,velocity] that player has hit
        self.newnotesofflist = [
        ]  # list of new note that player has taken fingers off of
        #self.noteson = set()    # set of notes that the player currently has down
        # commented out since it was crashing things to remove notes sometimes...
        self.pitchwheel = 64  # current value of the pitch wheel
        self.modwheel = 0  # current value of the mod wheel
        self.transientnotes = []
        pygame.midi.init()
Exemple #4
0
def playNote(angle, position, instr):
    fluidsynth.set_instrument(channel, instr)
    # transform angle
    note = int(((sin(angle[0]) + 1.0) / 2) * 100)
    volume = int(((sin(angle[1]) + 1.0) / 2) * 100)
    print note, volume
    fluidsynth.play_Note(note, channel, volume)
Exemple #5
0
 def run(self):
     # need to use bank_select
     fluidsynth.set_instrument(PLAYER_CHANNEL,
                               InstrumentNames["Acoustic Grand Piano"])
     fluidsynth.play_Note(self.note)
     self.event.wait()
     fluidsynth.stop_Note(self.note)
Exemple #6
0
    def play(self):
        eighth_time = 0.125
        beat_time = eighth_time * 2
        bar_time = beat_time * self.beat_count

        fluidsynth.set_instrument(1, 0)
        fluidsynth.play_NoteContainer(self.chord)

        next_notes = list(self.melody.notes)
        playing_notes = []

        for eighth in range(self.beat_count * 2):
            # bar boundary?
            if eighth % 8 == 0:
                self.play_chord()

            try:
                next_note = next_notes[0]
            except IndexError as e:
                # if this is the last note, the above will throw an IndexError
                pass

            if next_note.start_eighth == eighth:
                next_notes.remove(next_note)
                playing_notes.append(next_note)

                print('subbeat {}: PLAY FOR {}: {}'.format(
                    eighth, next_note.eighth_count, next_note.note))
                fluidsynth.set_instrument(1, 0)
                fluidsynth.play_Note(next_note.note)

            for mel_note in list(playing_notes):
                if eighth == mel_note.start_eighth + mel_note.eighth_count:
                    print('subbeat {}: STOP        {}'.format(
                        eighth, mel_note.note))

                    # don't stop the note if the same note is being played somewhere else!
                    note_played_elsewhere = False
                    for note in playing_notes:
                        # skip over this one, we're interested in other notes
                        if note == mel_note:
                            continue
                        if note.note == mel_note.note:
                            note_played_elsewhere = True

                    if not note_played_elsewhere:
                        fluidsynth.stop_Note(mel_note.note)

                    playing_notes.remove(mel_note)

            time.sleep(eighth_time)
        # we should have played the exact
        # if it isn't, something went wrong somewhere
        if len(playing_notes) != 0:
            #raise RuntimeError('playing_notes wasn\'t empty at the end of segment.play()!')
            print('EOS playing_notes: {}'.format(playing_notes))
            for mel_note in playing_notes:
                fluidsynth.stop_Note(mel_note.note)
                playing_notes.remove(mel_note)
def randInstrument(channel,
                   instr_list=set([x for x in range(0, 111)]) -
                   set([9, 18, 33, 55, 86, 92, 97, 101, 108])):
    # Some of the instruments have to be removed from the list because they are too
    # difficult to hear (e.g. pads that require long duration to reach normal volume).
    rand_instr = choice(tuple(instr_list))
    fluidsynth.set_instrument(channel, rand_instr)
    print("Instrument: " + str(rand_instr) + " - " + instr_name[rand_instr])
Exemple #8
0
def fluidsynth_init():
    '''
    fluidsynth_init - initializes fluidsynth to the soundfont file and sets the
    instrument for each channel according to the list in constants.py
    '''
    fluidsynth.init(general_soundfont, "alsa")
    for i in instruments:
        fluidsynth.set_instrument(i[0], i[1], i[2])
 def run(self):
     #takes the main loop and runs background tasks
     insturment = 1
     while 1:
         time.sleep(2)
         fluidsynth.set_instrument(0, insturment)
         insturment += 1
         if (insturment > 50):
             return
Exemple #10
0
 def run(self):
     #takes the main loop and runs background tasks
     insturment = 0
     while 1:
         time.sleep(15)
         print "instrument {0}".format(insturment)
         fluidsynth.set_instrument(2, insturment)
         insturment += 1
         if (insturment > 70):
             insturment = 0
Exemple #11
0
    def Open(self):

        pygame.mixer.init()
        pygame.mixer.music.load("short_music.wav")
        pygame.mixer.music.play()
        self.last_detect_time = time.time()

        fluidsynth.init('/usr/share/sounds/sf2/FluidR3_GM.sf2', "alsa")
        fluidsynth.set_instrument(0, 6)
        fluidsynth.set_instrument(1, 4)
Exemple #12
0
 def __init__(self,
              numSteps,
              scaleName="Diatonic",
              start_key='C',
              instrument=0,
              octave=4):
     self.numSteps = numSteps
     self.scaleName = scaleName
     self.start_key = start_key
     self.octave = octave
     fluidsynth.set_instrument(1, instrument)
     self.soundArr = self.__getSoundArr(self.octave)
def play_offset(off, sleep_s=0.2, song=sonata, repeats=5, down_octaves=1, instrument=None):
        song = song * repeats
        if instrument is not None:
                for i in range(off):
                        fluidsynth.set_instrument(i+1, instrument)
        for i in range(len(song)+off):
                to_stop = i - off
                if to_stop >= 0:
                        fluidsynth.stop_NoteContainer(NoteContainer([a + "-" + str(int(b)-down_octaves) for (a, b) in song[to_stop].split()]), channel=(to_stop%off)+1)
                if i < len(song):
                        fluidsynth.play_NoteContainer(NoteContainer([a + "-" + str(int(b)-down_octaves) for (a, b) in song[i].split()]), channel=(i%off)+1, velocity=127)
                time.sleep(sleep_s)
Exemple #14
0
def play_example(key):
	progression = ["I", "vi", "ii", "iii7",
	       "I7", "viidom7", "iii7", "V7"]

	# key = 'C'
	
	chord_list = progressions.to_chords(progression, key)

	fluidsynth.set_instrument(13, 45)
	fluidsynth.set_instrument(10, 24)

	while True:
		for chord in chord_list:
			play_solo_bar_with_chord(chords.determine(chord, shorthand=True)[0])
Exemple #15
0
    def setUp(self):
        soundfont = os.getenv("SOUNDFONT")
        if soundfont is None:
            raise ValueError(
                "A soundfont (*.sf2) file path must be provided in the SOUNDFONT environment variable"
            )

        self.tempdir = tempfile.mkdtemp()
        output_file = os.path.join(self.tempdir, "test.wav")

        fluidsynth.init(soundfont, file=output_file)
        fluidsynth.set_instrument(0, 0)
        s = SequencerObserver()
        fluidsynth.midi.attach(s)
Exemple #16
0
def play_smart_solo_over_chords(chord_list):
	fluidsynth.set_instrument(13, 45)
	fluidsynth.set_instrument(10, 108)

	fluidsynth.main_volume(13, 75)
	fluidsynth.main_volume(10, 100)
	
	solo = Track()

	bars = generate_solo(chord_list)
	for i in range(len(bars)):
		chord = NoteContainer(chords.from_shorthand(chord_list[i]))
		bar = bars[i]
		fluidsynth.play_NoteContainer(chord, 13)
		fluidsynth.play_Bar(bar, 10)
		fluidsynth.stop_NoteContainer(chord, 13)
		solo.add_bar(bar)
	return solo
Exemple #17
0
    def __init__( self ):
    # possible fluidsynth guys
##main_volume(channel, value)
##modulation(channel, value)
##pan(channel, value)

        if not fluidsynth.init( os.path.join( config.RESOURCEdirectory, config.SOUNDfont), 
            config.FLUIDSYNTHdriver ):
            sys.exit(" COULD NOT LOAD SOUNDFONT PianoMenu.sf2 ")
        # set instruments on each channel.  
        fluidsynth.set_instrument( config.PIANOchannel,    ## channel to set instrument on
                                   config.SOUNDfontPIANO ) ## instrument.  determined by sound font

        self.keysmod12 = [ "C", "C#", "D", "Eb", "E", "F", "F#", "G", "Ab", "A", "Bb", "B" ]
        self.keyson = [ 0 ]*12  # denotes all keys on in an octave
        self.newnotesonlist = [ ]   # list of new [note,velocity] that player has hit
        self.newnotesofflist = [ ]  # list of new note that player has taken fingers off of
        #self.noteson = set()    # set of notes that the player currently has down 
        # commented out since it was crashing things to remove notes sometimes...
        self.pitchwheel = 64    # current value of the pitch wheel
        self.modwheel = 0       # current value of the mod wheel
        self.transientnotes = []
        pygame.midi.init()
Exemple #18
0
    def __init__(self):

        if not fluidsynth.init(
                os.path.join(config.RESOURCEdirectory, config.SOUNDfont),
                config.FLUIDSYNTHdriver):
            sys.exit(" Kan de Fluidsynth Sountfont PianoMenu.sf2 niet laden ")
        # Een instrument geven aan je channels.
        fluidsynth.set_instrument(
            config.PIANOchannel,  ## channel voor je instrument.
            config.SOUNDfontPIANO)  ## instrument gebaseerd op je soundfont.

        self.keysmod12 = [
            "C", "C#", "D", "Eb", "E", "F", "F#", "G", "Ab", "A", "Bb", "B"
        ]
        self.keyson = [0] * 12  # Representeert alle keys in een octaaf
        self.newnotesonlist = [
        ]  # lijst van de noten die de gebruiker heeft aangeslagen.
        self.newnotesofflist = []  # Lijst van noten die gebruiker loslaat.
        #self.noteson = set()    # noten die gebruiker gebruikt.
        self.pitchwheel = 64
        self.modwheel = 0
        self.transientnotes = []
        pygame.midi.init()
Exemple #19
0
 def play(self):
     fluidsynth.set_instrument(1, 73)  # chords
     fluidsynth.set_instrument(2, 32)  # bass
     fluidsynth.set_instrument(3, 1, 128)  # drums
     fluidsynth.main_volume(1, 50)
     fluidsynth.main_volume(2, 100)
     fluidsynth.main_volume(3, 30)
     for bars in self._next_bar():
         fluidsynth.play_Bars(bars, [1, 2, 3], 110)
         yield self.current
Exemple #20
0
 def play(self):
     fluidsynth.set_instrument(1, 73) # chords
     fluidsynth.set_instrument(2, 32) # bass
     fluidsynth.set_instrument(3, 1, 128) # drums
     fluidsynth.main_volume(1, 50)
     fluidsynth.main_volume(2, 100)
     fluidsynth.main_volume(3, 30)
     for bars in self._next_bar():
         fluidsynth.play_Bars(bars, [1, 2, 3], 110)
         yield self.current
Exemple #21
0
	def set_instrument(self):
		if not(self.midi_set) and 'midi_instr' in self.params:
			if not self.no_fluidsynth:
				fluidsynth.set_instrument(self.params["channel"], self.params["midi_instr"])
			self.midi_set = True
			self.track.instrument.instrument_nr = self.params["midi_instr"]
Exemple #22
0
 def play_chord(self):
     fluidsynth.stop_NoteContainer(self.chord)
     fluidsynth.set_instrument(1, 0)
     fluidsynth.play_NoteContainer(self.chord)
Exemple #23
0
        8: ["Db", 340, 381],
    }
    return switcher.get(argument)


###############################################
### START of main

# create NoteContainer
n = NoteContainer()
n_1 = NoteContainer()
n_2 = NoteContainer()

# initialize synth
fluidsynth.init("/usr/share/sounds/sf2/FluidR3_GM.sf2", "alsa")
fluidsynth.set_instrument(1, 108)
fluidsynth.set_instrument(2, 53)
fluidsynth.set_instrument(3, 112)

for step in range(16, 100):
    """ fluidsynth.play_Note(64, 0, 100)
    sleep(1)
    fluidsynth.stop_Note(64, 0) """
    print("zoom x", 2**step)
    rate = 2**step
    amin = xcenter - 2 / rate
    amax = xcenter + 2 / rate
    aoffset = 0
    bmin = ycenter - 2 / rate
    bmax = ycenter + 2 / rate
    boffset = 0
Exemple #24
0
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
GRAY = (128, 128, 128)

size = width, height = (800, 700)
pygame.display.init()
screen = pygame.display.set_mode(size)
pygame.display.set_caption("LinMesia")

clock = pygame.time.Clock()

fluidsynth.init("/usr/share/sounds/sf2/FluidR3_GM.sf2", "jack")
fluidsynth.set_instrument(0, 0)

# banknum = 0
# # presetnum sets the instrument
# presetnum = 0
# channel = 0

# soundfont = "/usr/share/sounds/sf2/FluidR3_GM.sf2"
# fs = fluidsynth.Synth()
# fs.start()

# sfid = fs.sfload(soundfont)
# fs.program_select(channel, sfid, banknum, presetnum)

pianokeymap = [['q', 'w', 'e', 'r', 't', 'y', 'u', '2', '3', '5', '6', '7'],
               ['i', 'o', 'p', '[', ']', '\\', 'z', '9', '0', '-', '=', 'a']]
Exemple #25
0
 def set_instrument(self, channel, instrument):
     fluidsynth.set_instrument(channel, instrument)
 def setUp(self):
     fluidsynth.init('/usr/share/sounds/sf2/FluidR3_GM.sf2',
                     file='test.wav')
     fluidsynth.set_instrument(0, 0)
     s = SequencerObserver()
     fluidsynth.midi.attach(s)
Exemple #27
0
		def setInstrument(spinner, inst):
			fluidsynth.set_instrument(1, instrumentNames.index(inst))
Exemple #28
0
import time
import Adafruit_MPR121.MPR121 as MPR121 #12-key capacitive switch sensor
from sys import exit
from neopixel import * #colored lights
#midi player libraries
from mingus.core import notes, chords 
from mingus.containers import * 
from mingus.midi import fluidsynth
import RPi.GPIO as GPIO #for GPIO switch

#fluidsynth.init('/usr/share/sounds/sf2/FluidR3_GM.sf2',"alsa")
fluidsynth.init('/home/pi/Documents/Halloween Piano/soundFonts/Arachno SoundFont - Version 1.0.sf2',"alsa") #custom sound font sounds slightly better than FluidR3_GM.sf2, but file size is larger

#assign instruments to separate channel numbers (1 is hammond organ, 2 is steel guitar, etc...)
fluidsynth.set_instrument(1, 16) #16 hammond organ 
fluidsynth.set_instrument(2, 26) #26 steel guitar
fluidsynth.set_instrument(3, 0, 128) #0 Bank 128 standard drums
fluidsynth.set_instrument(4, 114) #114 steel drums
fluidsynth.set_instrument(5, 48, 128) #48 bank 128 orchestra drum kit
fluidsynth.set_instrument(6, 25, 128) #25 bank 128 TR-808 drum kit
fluidsynth.set_instrument(7, 102) #102 echo drops
fluidsynth.set_instrument(8, 11) #11 vibraphone
fluidsynth.set_instrument(9, 13) #13 xylophone
fluidsynth.set_instrument(10, 55) #55 orchestra hit
fluidsynth.set_instrument(11, 86) #5th saw wave
fluidsynth.set_instrument(12, 88) #fantasia
#instrument numbers: https://www.midi.org/specifications/item/gm-level-1-sound-set
#Use Polysynth desktop application to open sf2 files and find instrument and bank numbers

#setup GPIO button as input
GPIO.setmode(GPIO.BCM)
Exemple #29
0
def set_instrument(bank, instrument):
    fluidsynth.set_instrument(SYNTH_CHANNEL, instrument, bank)
 def cbInstrumentsChanged(self, idx):
     fluidsynth.set_instrument(0, idx)
Exemple #31
0
On launch the user will be prompted to select the red, blue and green balls.
These will then be positionally tracked and trigger the samples assigned to 
regions of "juggle space".

Controls:
-----
	ESC key  		- exit
	left mouse button	- report color of pixel under cursor
'''

import numpy as np
import cv2
from mingus.midi import fluidsynth

fluidsynth.init('/usr/share/sounds/sf2/FluidR3_GM.sf2',"alsa")
fluidsynth.set_instrument(0, 118)
fluidsynth.set_instrument(1, 114)
fluidsynth.set_instrument(2, 0)

class App(object):
	def __init__(self, video_src):
		self.cam = cv2.VideoCapture(video_src)
		ret, self.frame = self.cam.read()
		cv2.namedWindow('juggle-music')
		cv2.setMouseCallback('juggle-music', self.onmouse)

		# set up font for writing text
		self.font = cv2.FONT_HERSHEY_SIMPLEX

		# a dictionary of our tracked objects with their hue range
		self.objects = dict()
        "eeeeeeee", # 118
        "eeeeeeee", # 119
        "eeeeeeee", # 120
        "brrrcrrr", # 121	
	]

strike = Note("C-4")
rest = Note("C-7") # dummy note

tempo = 0.11712

fluidsynth.init("TypewriterInstruments.sf2")

carriageReturn = {'note':40,'inst':0} # note 40, instrument 0

fluidsynth.set_instrument(1,1) # set instrument 1 as chimes
bell = {'note':72,'inst':1}

fluidsynth.set_instrument(2,3) # instrument 2 is typewriter
typewriter = {'note':50,'inst':2}

rest = {'note':100,'inst':0} # dummy note for rest

for num,measure in enumerate(notes):
	#if (num+9) < 97: continue
	sys.stdout.write(str(num+9))
	sys.stdout.flush()
	for note in measure:
		if note=="e":
			note_to_play=typewriter
		elif note == "r":
Exemple #33
0
 def setinstrument(self, channel, instrument):
     fluidsynth.set_instrument(channel, instrument)
     print "setting channel", channel, "to instrument", instrument
Exemple #34
0
 def setinstrument( self, channel, instrument ):
     fluidsynth.set_instrument( channel, instrument )
     print "setting channel", channel, "to instrument", instrument
Exemple #35
0
	def setUp(self):
		fluidsynth.init("/home/bspaans/workspace/fluidsynth/ChoriumRevA.SF2")
		fluidsynth.set_instrument(0,0)
                s = SequencerObserver()
                fluidsynth.midi.attach(s)
Exemple #36
0
def test_instruments():
	for i in range(150):
		fluidsynth.set_instrument(13, 45)
		fluidsynth.set_instrument(10, i)
		print("Instrument number: {0}".format(i))
		play_smart_solo_over_chords(['Cm'])
Exemple #37
0
def play_Music(filename):
    f = open(filename, 'rb')
    data = json.loads(f.read(), encoding='utf8')
    f.close()

    n = data['音符']
    h = data['音高']
    r = data['节拍']
    l = data['组成']
    k = data['调性']
    t = Track()
    b = Bar('C', (4, 4))
    b.place_rest(1)
    t.add_bar(b)
    name = 'CDEFGAB'
    symbol = '!@#$%^&'

    def tran(x):
        if x >= 'a':
            return ord(x) - 87
        elif x == '0':
            return 0.5
        else:
            return float(x)

    f = open(filename, 'rb')
    data = json.loads(f.read(), encoding='utf8')
    f.close()

    n = data['音符']
    h = data['音高']
    r = data['节拍']
    l = data['组成']
    k = data['调性']
    t = Track()
    b = Bar('C', (4, 4))
    b.place_rest(1)
    t.add_bar(b)
    name = 'CDEFGAB'
    symbol = '!@#$%^&'
    for i in range(len(l)):
        rn = list(map(tran, r[l[i]]))
        b = Bar('C', (4 * sum(rn)/8, 4))
        for j in range(len(n[l[i]])):
            if n[l[i]][j] == '0':
                b.place_rest(8 / rn[j])
            else:
                x = symbol.find(n[l[i]][j])
                if x == -1:
                    x = int(n[l[i]][j]) - 1
                    y = name[x]
                else:
                    y = name[x] + '#'
                    print(y)
                note = Note(y, int(h[l[i]][j]))
                note.transpose(k[i])
                b.place_notes(note, 8 / rn[j])
        t.add_bar(b)

    t2 = Track()
    b = Bar('C', (4, 4))
    b.place_rest(1)
    t2.add_bar(b)
    for i in range(int(sum(map(sum, map(lambda x: map(tran, r[x]), l)))) // 8):
        b = Bar('C', (4, 4))
        b.place_notes('C-3', 4)
        b.place_notes('C-7', 4)
        b.place_notes('C-5', 4)
        b.place_notes('C-7', 4)
        t2.add_bar(b)

    m = MidiFile()
    mt = MidiTrack(150)
    mt2 = MidiTrack(150)
    mt3 = MidiTrack(150)
    m.tracks = [mt,mt2,mt3]
    mt.set_instrument(1, 25)
    mt.play_Track(t)
    # for _, _, i in t2.get_notes():
    #     if i is not None:
    #         i[0].set_channel(2)
    # mt2.set_instrument(2, 115)
    # mt2.play_Track(t2)
    # for _, _, i in t.get_notes():
    #     if i is not None:
    #         i[0].set_channel(3)
    # mt3.set_instrument(3, 100)
    # mt3.track_data += mt3.controller_event(3, 7, 30)
    # mt3.play_Track(t)
    # m.write_file('D:/test.midi', False)
    # for i in range(len(l)):
    #     rn = list(map(tran, r[l[i]]))
    #     b = Bar('C', (4 * sum(rn) / 8, 4))
    #     for j in range(len(n[l[i]])):
    #         # if i==0 and j==0:
    #         #     b.place_notes('D-4', 3)
    #         # el
    #         if n[l[i]][j] == '0':
    #             b.place_rest(1 / rn[j])
    #         else:
    #             x = symbol.find(n[l[i]][j])
    #             if x == -1:
    #                 x = int(n[l[i]][j]) - 1
    #                 y = name[x]
    #             else:
    #                 y = name[x] + '#'
    #                 print(y)
    #
    #             note = Note(y, int(h[l[i]][j]))
    #             note.transpose(k[i])
    #             #print(note)
    #             print(rn[j])
    #             #print(b)
    #             b.place_notes(note, 1 / rn[j])
    #     t.add_bar(b)
    #     print(b)

    fluidsynth.init("D:\MyCode\MyPython\AiMusicCoach\GeneralUserSoftSynth\GeneralUserSoftSynth.sf2")
    fluidsynth.set_instrument(1, 1)            #24=Nylon Guitar
                                                # 25=Steel Guitar
                                                # 26=Jazz Guitar
                                                # 27=Clean Guitar
                                                # 28=Muted Guitar
                                                # 29=Overdrive Guitar
                                                # 30=Distortion Guitar
    m.write_file('D:\MyCode\MyPython\AiMusicCoach\Backend\music_file\mysong.midi', False)
    os.system("d: && cd D:\\MyCode\\MyPython\\AiMusicCoach\\fluidsynth-x64\\bin && fluidsynth -F mysong.wav D:/MyCode/MyPython/AiMusicCoach/GeneralUserSoftSynth/GeneralUserSoftSynth.sf2 D:\MyCode\MyPython\AiMusicCoach\Backend\music_file\mysong.midi")
    fluidsynth.play_Track(t, channel=1, bpm=150)
Exemple #38
0
#!/usr/bin/env python
import sys, time
from mingus.midi import fluidsynth
from mingus.containers import Note, NoteContainer

if sys.platform == 'linux2':
    fluidsynth.init('GeneralUser GS v1.471.sf2', 'alsa')
else:
    fluidsynth.init('GeneralUser GS v1.471.sf2')

fluidsynth.set_instrument(1, int(sys.argv[1]), int(sys.argv[2]))

c = Note("C-4")
e = Note("E-4")
g = Note("G-4")

fluidsynth.play_Note(c)
time.sleep(2)

fluidsynth.play_Note(e)
time.sleep(2)

fluidsynth.play_Note(g)
time.sleep(2)

fluidsynth.stop_Note(c)
fluidsynth.stop_Note(e)
fluidsynth.stop_Note(g)
time.sleep(2)

nc = NoteContainer(["C-4", "E-4", "G-4"])
Exemple #39
0
import time

from constants import *
from read_signals import *
from mingus.midi import fluidsynth

PATH_TO_FIFO = "/home/pi/ECE5725-Final/akai_fifo"

fluidsynth.init("/home/pi/ECE5725-Final/sound_fonts/gen.sf2", "alsa")
fluidsynth.set_instrument(1, 13, 0)
track = []

def record():
    time.sleep(3)
    print ("start")
    start = time.time()
    recording = True
    while recording:
        with open(PATH_TO_FIFO) as fifo:
            for line in fifo:
                if reControlChange.match(line):
                    recording = False
                    break
                else:
                    if reNoteOn.match(line):
                        m = reNoteOn.match(line)
                        obj = NoteSignal("akai",time.time()-start,int(m.group(2)),int(m.group(3)),True)
                        track.append(obj)
                        obj.play()
                    if reNoteOff.match(line):
                        m = reNoteOff.match(line)
Exemple #40
0
 def setUp(self):
     fluidsynth.init('/home/bspaans/workspace/fluidsynth/ChoriumRevA.SF2',
                     file='test.wav')
     fluidsynth.set_instrument(0, 0)
     s = SequencerObserver()
     fluidsynth.midi.attach(s)
Exemple #41
0
from kivy.uix.button import Button
from kivy.uix.label import Label
from kivy.uix.boxlayout import BoxLayout
from kivy.uix.floatlayout import FloatLayout
from mingus.core import notes, chords
from mingus.containers import *
from random import random
from math import ceil

from mingus.midi import fluidsynth
fluidsynth.init('fluid.sf2') #set soundfont

#initialize default settings
#these are changed by buttons
#so they are declared here globally
fluidsynth.set_instrument(1, 0)
octaveSet = 2
keySet = 'C'
scaleSet = 'Major'
notesChange = True #keep track of changes, so we don't have to recompute unnecessarily
allScales = {}
currentNotes = []

class SlateWidget(Widget):
	notesp = {} #contain playing notes
		
	def on_touch_down(self, touch):
		#draw pretty lines on screen, inspired by online demo
		color = (random(), random(), random())
		with self.canvas:
			Color(*color)
 def setInstrument(self, num):
     fs.set_instrument(1, num)