Esempio n. 1
0
def easy_play(notes, durations=None, bpm=None):
    """`notes` should be a list of notes and/or note_containers.
    durations will all default to 4 (quarter notes).
    bpm will default current BPM setting, `st.BPM`."""
    if not bpm:
        bpm = st.BPM
    fluidsynth.play_Bar(easy_bar(notes, durations), bpm=bpm)
    def playManyNotes(self, notes):
        """Plays the next note in the song and advances the index"""
        tempBar = Bar()
        tempBar.set_meter((len(notes) * 4, 4))
        for n in notes:
            tempBar.place_notes(n, 1)

        fs.play_Bar(tempBar, 1, 200)
def playBeforeAnswer(randPassage):
    while (True):
        fluidsynth.play_Bar(randPassage)
        ans = input("Press R to replay, enter for answer.> ")
        if ans.lower() == "r":
            pass
        else:
            return
    def playNextNoteLong(self):
        """Plays the next note in the song and advances the index"""
        tempBar = Bar()
        tempBar.set_meter((1, 1))
        tempBar.key = self._key
        tempBar.place_notes(self._notes[self._index], 1)

        fs.play_Bar(tempBar, 120)
def playAfterAnswer(randPassage):
    while (True):
        again = input(
            "Type X to quit to menu, R to replay, enter for a new dictation.> "
        )
        if again.lower() == "x":
            return (False)
        elif again.lower() == "r":
            fluidsynth.play_Bar(randPassage)
        else:
            return (True)
Esempio n. 6
0
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)                      
    def playNextNote(self):
        """Plays the next note in the song and advances the index"""
        tempBar = Bar()
        beats = 1.0 / (1.0 / self._beat) / (1.0 / self._durs[self._index])
        tempBar.set_meter((beats, self._beat))
        tempBar.key = self._key
        tempBar.place_notes(self._notes[self._index], self._durs[self._index])

        print tempBar

        fs.play_Bar(tempBar, self._bpm)

        return self._index
Esempio n. 8
0
 def test_changing_bpm_bar(self):
     b = Bar()
     n = NoteContainer(['C', 'E', 'G'])
     n.bpm = 150
     b + NoteContainer(['A', 'C', 'E'])
     b + Note('E')
     b + n
     b + Note('Eb')
     self.assert_(fluidsynth.play_Bar(b, 0, 120))
Esempio n. 9
0
 def test_changing_bpm_bar(self):
     b = Bar()
     n = NoteContainer(['C', 'E', 'G'])
     n.bpm = 150
     b + NoteContainer(['A', 'C', 'E'])
     b + Note('E')
     b + n
     b + Note('Eb')
     self.assert_(fluidsynth.play_Bar(b, 0, 120))
Esempio n. 10
0
	def test_changing_bpm_bar(self):
		b = Bar()
		n = NoteContainer(["C", "E", "G"])
		n.bpm = 150
		b + NoteContainer(["A", "C", "E"])
		b + Note("E")
		b + n
		b + Note("Eb")
		self.assert_(fluidsynth.play_Bar(b, 0, 120))
Esempio n. 11
0
 def test_changing_bpm_bar(self):
     b = Bar()
     n = NoteContainer(["C", "E", "G"])
     n.bpm = 150
     b + NoteContainer(["A", "C", "E"])
     b + Note("E")
     b + n
     b + Note("Eb")
     self.assertTrue(fluidsynth.play_Bar(b, 0, 120))
Esempio n. 12
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
Esempio n. 13
0
	def test_bar_velocity(self):
		b = Bar()
		n = Note("C")
		n.velocity = 0
		m = Note("C")
		m.velocity = 40
		o = Note("C")
		o.velocity = 80
		p = Note("C")
		p.velocity = 120
		b + n
		b + m
		b + o
		b + p
		self.assert_(fluidsynth.play_Bar(b), 0)
Esempio n. 14
0
 def test_bar_velocity(self):
     b = Bar()
     n = Note("C")
     n.velocity = 0
     m = Note("C")
     m.velocity = 40
     o = Note("C")
     o.velocity = 80
     p = Note("C")
     p.velocity = 120
     b + n
     b + m
     b + o
     b + p
     self.assertTrue(fluidsynth.play_Bar(b), 0)
Esempio n. 15
0
	def test_playbar(self):
		b = Bar()
		b + Note("C")
		b + Note("E")
		b + Note("G")
		self.assert_(fluidsynth.play_Bar(b), 0)
Esempio n. 16
0
	def play_seventh_chord(choice, key):
		fs.play_Bar(get_bar_from_chord(SEVENTH_CHORD_FUNCS[choice](key)))
Esempio n. 17
0
	def play_triad(choice, key):
		fs.play_Bar(get_bar_from_chord(TRIAD_FUNCS[choice](key)))
Esempio n. 18
0
 def play_bar(self):
     fluidsynth.play_Bar(self.bar)
    def playNote(self, note):
        """Plays the next note in the song and advances the index"""
        tempBar = Bar()
        tempBar.place_notes(note, 1)

        fs.play_Bar(tempBar, 1, 200)
Esempio n. 20
0
#!/usr/bin/env python2
import mingus.containers as c
from mingus.midi import fluidsynth, MidiFileOut

sf = '/usr/share/soundfonts/Unison.sf2'
fluidsynth.init(sf, 'alsa')

bar = c.Bar()
bar + c.Note('A',4)
bar + c.Note('B',4)
bar + c.Note('C',4)
bar + c.Note('D',4)
print(bar)

for _ in range(10):
    print('Play')
    fluidsynth.play_Bar(bar)
    def playChord(self, note1, note2):
        """Plays the next note in the song and advances the index"""
        tempBar = Bar()
        tempBar.place_notes([note1, note2], 1)

        fs.play_Bar(tempBar, 1, 200)
Esempio n. 22
0
 def test_playbar(self):
     b = Bar()
     b + Note('C')
     b + Note('E')
     b + Note('G')
     self.assert_(fluidsynth.play_Bar(b), 0)
Esempio n. 23
0
 def play_chord(choice, key):
     fs.play_Bar(get_bar_from_triad(CHORD_FUNCS[choice](key)))
Esempio n. 24
0
 def test_playbar(self):
     b = Bar()
     b + Note('C')
     b + Note('E')
     b + Note('G')
     self.assert_(fluidsynth.play_Bar(b), 0)
Esempio n. 25
0
 def test_playbar(self):
     b = Bar()
     b + Note("C")
     b + Note("E")
     b + Note("G")
     self.assertTrue(fluidsynth.play_Bar(b), 0)
Esempio n. 26
0
 def next_bar(self):
     self.bar = self.random_bar()
     fluidsynth.play_Bar(self.bar)
def speedDrill():
    print("""INPUT FORMAT:
You are expected to type the letter name (A, B, C, etc.) with your left hand.
Your right hand will type the accidental. , = flat . = natural / = sharp
This is meant to roughly even out the effort for typing each note, whether
F# or C; but if you wish, you may also enter a standard name, e.g. A4, C#3, Eb6.
Inputs are not case sensitive.

If you cannot hear a pitch, enter S to skip that question. Type X to quit.\n"""
          )
    ## TO DO: Give a report card of average times and accuracy for each pc.
    ## Also, make timer interrupt any raw_input. (Right now it only checks timer when the loop iterates.)
    while (True):
        try:
            timelimit = int(input("Enter time limit in minutes (1-5) > "))
            if timelimit >= 1 and timelimit <= 5:
                timelimit = timelimit * 60.0
                break
        except ValueError:
            pass

    while (True):
        octaves = input("Test octaves? (Y/N) > ")
        if octaves.lower() == "y":
            octaves = True
            break
        elif octaves.lower() == "n":
            octaves = False
            break
        else:
            pass

    score = 0
    attempts = 1

    input("Press ENTER to begin.")
    startTime = time.time()

    while (time.time() - startTime < timelimit):
        randInstrument(1)

        randPitch = Note(12 * randint(3, 6) + randint(0, 12))
        randBar = Bar()
        randBar.place_notes(randPitch, 4)
        fluidsynth.play_Bar(randBar)

        ans1 = ans2 = altans1 = altans2 = "x"
        # Create two possible answers for black keys. ans1 is the "preferred" answer.
        # Only ans1 will be printed and needs mixed case; the others are only for
        # internal comparison and are assigned lowercase only.
        if randPitch.name == "C#":
            ans1 = "C#"
            altans1 = "c/"
            ans2 = "db"
            altans2 = "d,"
        elif randPitch.name == "D#":
            ans1 = "Eb"
            altans1 = "e,"
            ans2 = "d#"
            altans2 = "d/"
        elif randPitch.name == "F#":
            ans1 = "F#"
            altans1 = "f/"
            ans2 = "gb"
            altans2 = "g,"
        elif randPitch.name == "G#":
            ans1 = "G#"
            altans1 = "g/"
            ans2 = "ab"
            altans2 = "a,"
        elif randPitch.name == "A#":
            ans1 = "Bb"
            altans1 = "b,"
            ans2 = "a#"
            altans2 = "a/"
        else:
            ans1 = randPitch.name
            ans2 = ans1.lower()
            altans1 = ans2 + "."
            altans2 = altans1

        if (octaves):
            ans1 = ans1 + str(randPitch.octave)
            ans2 = ans2 + str(randPitch.octave)
            altans1 = altans1 + str(randPitch.octave)
            altans2 = altans2 + str(randPitch.octave)

        correct = False

        guess = input("Enter guess. > ")

        if guess.lower() == "s":
            print("Skipped.")
        elif guess.lower() == "x":
            break
        elif guess.lower() == ans1.lower() or guess.lower(
        ) == ans2 or guess.lower() == altans1 or guess.lower() == altans2:
            score += 1
            print("CORRECT ({0}). SCORE: {1}/{2} ({3}%)".format(
                ans1, score, attempts, round(100 * float(score) / attempts),
                2))
            attempts += 1
        else:
            print("* WRONG ({0}). SCORE: {1}/{2} ({3}%)".format(
                ans1, score, attempts, round(100 * float(score) / attempts),
                2))
            attempts += 1

    print("Time's up.")
def targetYN():
    print(
        "GOAL: Choose a target pitch. Listen to a random melody: is the target pitch in there? If yes, play it again, and type in the index of the pitch (i.e. what number does it fall in the sequence: 1, 2, 3 ...).\n"
    )
    pcSought_in = input("Which pc are you listening for? (0-11) > ")

    try:
        pcSought = int(pcSought_in)
    except:
        print("Error. Please type an integer 0-11.")
        return

    if pcSought < 0 or pcSought > 11:
        print("Error. Please type an integer 0-11.")

    numnotes_in = input("Please choose a melody length. (1-16) > ")

    try:
        numnotes = int(numnotes_in)
    except:
        print("Error. Please type an integer 1-16.")
        return

    if numnotes < 1 or numnotes > 16:
        print("Error. Please type an integer 1-16.")
        return

    loopTarget = True

    while (loopTarget):
        randInstrument(1)

        randNotes = []
        randBar = Bar()
        randBar.set_meter((numnotes, 4))
        pitch_list = []
        for i in range(0, numnotes):
            randPitch = Note(12 * randint(3, 6) + randint(0, 12))
            randNotes.append(randPitch)
            pitch_list.append(notes.note_to_int(randPitch.name))
            randBar.place_notes(randPitch, 4)

        fluidsynth.play_Bar(randBar)

        note_present = False
        if (pcSought in pitch_list):
            note_present = True

        present_in = input("Was the desired note present? (Y/N) > ")

        player_thinks = False

        if present_in.lower() == "y":
            player_thinks = True

        if player_thinks == note_present:
            print("Correct! The note", end="")
            if note_present:
                print(" was present.\n")
            else:
                print(" was not present.\n")
        else:
            print("Incorrect. The note\n", end="")
            if note_present:
                print(" was present.\n")
            else:
                print(" was not present.\n")

        if note_present:
            print(
                "Press ENTER to replay, then type where in the sequence the note appears."
            )
            fluidsynth.play_Bar(randBar)
            locations_in = input(
                "Enter the indices of the note, starting with 1, and separated by spaces. > "
            )
            #string processing: make an array from the input. Make an array of the pitch locations. Compare. Are they correct? Output the array.

        print(randNotes)
        loopTarget = playAfterAnswer(randBar)
Esempio n. 29
0
def play_solo_bar_with_chord(chord_name):
	chord = NoteContainer(chords.from_shorthand(chord_name))
	solo = solo_bar(chord_name)
	fluidsynth.play_NoteContainer(chord, 13)
	fluidsynth.play_Bar(solo, 10)
	fluidsynth.stop_NoteContainer(chord, 13)
Esempio n. 30
0
 def play_interval(choice, key):
     fs.play_Bar(get_bar_from_interval([key, INTERVAL_FUNCS[choice](key)]))