Ejemplo n.º 1
0
def getSingleObj(fx, fy, gx, gy):
    """ Get 2 note objects and keep writing them. """
    """ X direction indicates pitches. """
    """ Y direction indicates octaves. """
    a = Note(value=int(fx/53), volume=int(fy/48)*12)
    b = Note(value=int(gx/53), volume=int(fy/48)*12)
    return a, b
Ejemplo n.º 2
0
 def test_init_empty(self):
     """Test if NoteSeq without arguments will clean previous values."""
     seq = NoteSeq()
     seq.append(Note("C"))
     seq = NoteSeq()
     seq.append(Note("D"))
     self.assertEqual(seq, NoteSeq("D"))
Ejemplo n.º 3
0
    def makemidi(self):
        note_names = 'c c# d d# e f f# g g# a a# b'.split()
        octav10 = {
            'c10', 'c#10', 'd10', 'd#10', 'e10', 'f10', 'f#10', 'g10', 'g#10',
            'a10', 'a#10', 'b10'
        }

        result = NoteSeq()
        for s in self.song:
            duration = 1. / s[1]

            if s[0] == 'r':
                result.append(Rest(dur=duration))
            elif {s[0]}.issubset(octav10):
                md = s[0][:-2]
                octave = int(s[0][-2:]) + 1
                note_number = note_names.index(md)
                result.append(Note(note_number, octave=octave, dur=duration))
            else:
                md = s[0][:-1]
                octave = int(s[0][-1]) + 1
                note_number = note_names.index(md)
                result.append(Note(note_number, octave=octave, dur=duration))

        midi = Midi(number_tracks=1, tempo=self.bpm)
        midi.seq_notes(result, track=0)
        midi.write(self.path)
Ejemplo n.º 4
0
 def addPause(self, note):
     firstNote = self.__notes[0]
     n = Note("A")
     n.octave = firstNote.octave
     n.volume = 0
     n.dur = firstNote.dur
     self.__notes.append(note)
Ejemplo n.º 5
0
def demo():
    notes1 = NoteSeq("D4 F#8 A Bb4")
    notes2 = NoteSeq([Note(2, dur=1/4), Note(6, dur=1/8),
                      Note(9, dur=1/8), Note(10, dur=1/4)])
    midi = Midi(number_tracks=2, tempo=90)
    midi.seq_notes(notes1, track=0)
    midi.seq_notes(notes2, track=1)
    midi.write("midi/demo.mid")
Ejemplo n.º 6
0
 def test_init_string(self):
     seq1 = NoteSeq([Note(0, 4, 0.125), Note(2, 4, 0.125)])
     seq2 = NoteSeq([Note(0, 6, 0.125), Rest(0.25)])
     seq3 = NoteSeq([Note(0, 5, 0.25), Note(2, 5, 0.25)])
     self.assertEqual(NoteSeq("C8, D"), seq1)
     self.assertEqual(NoteSeq("c8, d"), seq1)
     self.assertEqual(NoteSeq("c8'' r4"), seq2)
     self.assertEqual(NoteSeq("C8'' R4"), seq2)
     self.assertEqual(NoteSeq("C D"), seq3)
Ejemplo n.º 7
0
 def test_init_with_rest(self):
     seq1 = NoteSeq("C4 R4 D4")
     seq2 = NoteSeq("C8 R D")
     seq3 = NoteSeq([Note(0, dur=0.25), Rest(0.25), Note(2, dur=0.25)])
     self.assertEqual(seq1[0].dur, 0.25)
     self.assertEqual(seq1[1].dur, 0.25)
     self.assertEqual(seq1[2].dur, 0.25)
     self.assertEqual(seq2[0].dur, 0.125)
     self.assertEqual(seq2[1].dur, 0.125)
     self.assertEqual(seq2[2].dur, 0.125)
     self.assertEqual(seq3[0].dur, 0.25)
     self.assertEqual(seq3[1].dur, 0.25)
     self.assertEqual(seq3[2].dur, 0.25)
Ejemplo n.º 8
0
def note_from_key_number(k, octave=0):
    if isinstance(k, Note): return k
    if isinstance(k, int): return Note(k - 51 + octave * 12)
    lst = []
    for x in k:
        lst.append(note_from_key_number(x, octave=octave))
    return lst
Ejemplo n.º 9
0
def generate(key, outfile):
    # scale = open("./scales/"+key,"r")
    cipher = open("c_text", "r")
    dur = open("c_dur", "r")

    notes1 = []
    #using for getting the data and creating lits.
    while True:
        ci = cipher.readline()
        du = dur.readline()
        if not ci or not du:
            break
        c = int(ci)
        d = float(du)
        notes1.append(Note(value=c, dur=d))

    for note in notes1:
        print(note)

    midi = Midi(1, tempo=80)
    midi.seq_notes(notes1, track=0)
    midi.write("inter.mid")
    cipher.close()
    dur.close()
    os.remove("c_text")
    os.remove("c_dur")
    meta.meta("inter.mid", key, outfile)
Ejemplo n.º 10
0
def get_meter_notes(beats_sample,
                    meter_signature,
                    pitch_sample,
                    octave_sample,
                    volume_sample=120,
                    shuffle_pitch_sample=True,
                    shuffle_beats=True,
                    n_beats=None):
    """ Return the sequence of notes
    """
    notes = NoteSeq()
    # get the beats
    if shuffle_beats:
        beats = get_beats(beats_sample, meter_signature)
    else:
        beats = beats_sample

    if n_beats:
        beats = beats[:n_beats]

    vol = get_random_item(volume_sample)

    for ctr, beat in enumerate(beats):

        if shuffle_pitch_sample:
            pitch = get_random_item(pitch_sample)
        else:
            pitch = pitch_sample[ctr]
        note = pitch_to_note(pitch)
        octave = get_random_item(octave_sample)

        notes.append(Note(note, octave, beat, vol))
    return notes
Ejemplo n.º 11
0
def midi_from_melodies(melodies):
	notes = [[Note(x%Octave, 4 + x//Octave, 1/4) for x in melody] for melody in melodies]
	chords = [NoteSeq([melody_notes[i] for melody_notes in notes]) for i in range(len(melody))]

	midi = Midi(tempo=120)
	midi.seq_chords(chords)
	return midi
Ejemplo n.º 12
0
def chord_prog(chords_note):
    cprog6251 = NoteSeq()
    count = 0
    while count < 2:  # while true if break
        for i in chords_note:
            cprog6251.append(Note(i, 4, 1, 100))
        count += 1
    return cprog6251
Ejemplo n.º 13
0
 def test_init(self):
     n1 = Note("C")
     n2 = Note(value=6, octave=6, dur=0.125, volume=120)
     n3 = Note()
     n4 = Note(2)
     self.assertEqual(n1, Note(0))
     self.assertEqual(n2, Note(6, 6, 0.125, 120))
     self.assertEqual(n2, Note("F#8''", volume=120))
     self.assertEqual(n3, n1)
     self.assertEqual(n4, Note("D"))
Ejemplo n.º 14
0
def random_notes(pitch_list, octave, duration, number_of_notes, volume=120):
    result = NoteSeq()
    for x in range(0, number_of_notes):
        pitch = choice(pitch_list)
        octave = choice_if_list(octave)
        dur = choice_if_list(duration)
        vol = choice_if_list(volume)
        result.append(Note(pitch, octave, dur, vol))
    return result
Ejemplo n.º 15
0
    def test_chord_created_using_note_objects(self):
        # create notes
        soprano = Note("G'")
        alto = Note("E'")
        tenor = Note("C'")
        bass = Note("C,")
        # create chord from given notes
        c_chord = Chord(soprano, alto, tenor, bass)
        # check if chord consists of given notes
        self.assertEqual(c_chord.soprano, soprano)
        self.assertEqual(c_chord.alto, alto)
        self.assertEqual(c_chord.tenor, tenor)
        self.assertEqual(c_chord.bass, bass)

        self.assertIs(type(c_chord.soprano), Note)
        self.assertIs(type(c_chord.alto), Note)
        self.assertIs(type(c_chord.tenor), Note)
        self.assertIs(type(c_chord.bass), Note)
Ejemplo n.º 16
0
def end(notes, scale):
    print(notes.items, scale, (scale - 1) % 7)
    end1 = Music.scaleInvertAtIndex(notes, scale, choice([4, 6]))
    end1.reverse()
    end1 += NoteSeq([Note(scale, octave=5, dur=0.5)])
    if scale == 0:
        end1[-1].octave += 1
    print("end:", end1.verbose)
    return end1
Ejemplo n.º 17
0
def play_list(pitch_list, octave_list, duration, volume=120):
    result = NoteSeq()
    for pitch in pitch_list:
        note = pitch % 12
        octave = choice_if_list(octave_list)
        dur = choice_if_list(duration)
        vol = choice_if_list(volume)
        result.append(Note(note, octave, dur, vol))
    return result
Ejemplo n.º 18
0
def from_pitch_track(times, pitch, sample_rate, filename="tmp.midi"):
    midi_notes = [to_midi(x) for x in pitch]
    notes = compact(midi_notes, step=(times[1] - times[0]) / sample_rate / 2)
    track0 = [Note(x, 0, round(t, 4)) if not np.isnan(x) else Rest(dur=round(t, 4)) for x, t in notes]
    m = Midi(1, tempo=90)
    m.seq_notes(track0, track=0)

    m.write(filename)
    return filename
Ejemplo n.º 19
0
 def test_harmonize(self):
     c_major_scale = NoteSeq("C D E F G A B")
     scale_as_list = [
         Note("C"),
         Note("D"),
         Note("E"),
         Note("F"),
         Note("G"),
         Note("A"),
         Note("B")
     ]
     c_major = Note("C").harmonize(c_major_scale, 3, 3)
     a_minor = Note("A").harmonize(scale_as_list, 3, 4)
     self.assertEqual(NoteSeq(c_major), NoteSeq("C E G"))
     self.assertEqual(NoteSeq(a_minor), NoteSeq("A C'' E G"))
Ejemplo n.º 20
0
def random_notes(pitch_list, octave_list, duration, volume):
    result = NoteSeq()
    number_of_notes = int(1 // duration)
    for x in range(0, number_of_notes, 1):
        pitch = choice(pitch_list)
        octave = choice(octave_list)
        dur = duration
        vol = volume
        result.append(Note(pitch, octave, dur, vol))
    return result
Ejemplo n.º 21
0
def form_seq(appregio_notes):
    sequence = []
    # for a, b in zip(appregio_notes, notes_5th):
    # 	sequence.append(Note(a).stretch_dur(0.5))
    # 	sequence.append(Note(a).stretch_dur(0.5).transposition(b))
    for i in appregio_notes:
        sequence.append(Note(i, 5, 0.125 / 2, 100))
    notes = NoteSeq(sequence)
    print(notes)
    return notes
Ejemplo n.º 22
0
def josquin():
    main_theme = NoteSeq("file://josquin")
    theme1 = main_theme.stretch_dur(0.66666)
    theme2 = main_theme[0:24].stretch_dur(2).transp(Note("C"))
    theme3 = main_theme[0:50]

    midi = Midi(3, tempo=80)
    midi.seq_notes(theme1, track=0)
    midi.seq_notes(theme2, track=1)
    midi.seq_notes(theme3, track=2)
    midi.write("midi/josquin.mid")
Ejemplo n.º 23
0
    def test_sum_with_note(self):
        #  Test adding in regular order
        note1 = Note("G1")
        seq = NoteSeq("C2 D8 E4")
        expected = NoteSeq("C2 D8 E4 G1")
        self.assertEqual(seq + note1, expected)

        #  Test reverse adding, note first
        seq = NoteSeq("C2 D8 E4")
        expected = NoteSeq("G1 C2 D8 E4")
        self.assertEqual(note1 + seq, expected)
Ejemplo n.º 24
0
def getNotesFromNums(nums, scaleNum, durations):
    #convert back to noteSeq
    scale = majorScales[scaleNum]
    ans = NoteSeq()
    j = 0
    for num in nums:
        for i in range(len(scale)):
            if num==i:
                ans.append(Note(scale[i], dur=durations[j]))
                j+=1
    #print(ans)
    return ans
Ejemplo n.º 25
0
def canon():
    theme1 = NoteSeq("file://canon-quaerendo-invenietis")
    part1 = theme1 + theme1[2:] + theme1[2:11]
    part2 = theme1 + theme1[2:] + theme1[2:4]

    voice1 = part1
    voice2 = part2.inversion_startswith(Note(2, 4))

    midi = Midi(2, tempo=150)
    midi.seq_notes(voice1, time=3, track=0)
    midi.seq_notes(voice2, time=13, track=1)
    midi.write("midi/canon.mid")
Ejemplo n.º 26
0
def fusion_prog_rym(rm_data, root, seventh, nine):
    # note indicates which note in the chord you want to put in the seq
    fsprogr = NoteSeq()
    fsprog7 = NoteSeq()
    fsprog9 = NoteSeq()
    fsprog = [fsprogr, fsprog7, fsprog9]
    # the note of melody could be the 1, b3, 3, 5, b7, 7th of the chord
    pitch_in_chord = [0, 3, 4, 7, 10, 11]
    melody_len = 0
    for p in rm_data:
        melody_len += p[2]
        r = random.choice(pitch_in_chord)
        se = random.choice(seventh)
        if p[2] == 0.25:
            fsprogr.append(Note(p[0] - r, 4, p[2], 100))
            fsprog7.append(Note(p[0] - r + se, 4, p[2], 100))
            fsprog9.append(Note(p[0] - r + 14, 4, p[2], 100))
        elif p[2] == 0.5:
            fsprogr.append(Note(p[0] - r, 4, p[2], 100))
            fsprog7.append(Note(p[0] - r + se, 4, p[2], 100))
            fsprog9.append(Note(p[0] - r + 14, 4, p[2], 100))
        elif p[2] == 0.125:
            fsprogr.append(Rest(p[2]))
            fsprog7.append(Rest(p[2]))
            fsprog9.append(Rest(p[2]))
    return fsprog
Ejemplo n.º 27
0
def create_midi_with_time(music, beat_of_music):
    global LEN_OF_MUSIC
    noteSeq = []
    for i in range(LEN_OF_MUSIC):
        if music[i] == 101:
            noteSeq.append(Rest(dur=beat_of_music[i]))
        else:
            noteSeq.append(Note(music[i], dur=beat_of_music[i]))

    seq = NoteSeq(noteSeq)
    midi = Midi(number_tracks=1, tempo=90)
    midi.seq_notes(seq, track=0)
    midi.write("midi/markov_Gavotte_test1.mid")
Ejemplo n.º 28
0
    def symbol2Note(self, symbol):
        if (symbol.name.islower()):
            n = Note(symbol.name.upper() + '#')
        else:
            n = Note(symbol.name)
        n.octave = self.getOctave()
        n.volume = self.getVolume()
        # 60 bpm faz uma batida por segundo, e uma batida é uma semínima (0.25)
        n.dur = (60 / self.getBeat()) / 4

        return n
Ejemplo n.º 29
0
def obs_to_note(obs):
    global notes
    day, hour, temp, opacity, precip = obs
    # Temperature is note
    index = int(temp)
    if index < 7: index = 7
    elif index > 90: index = 90
    index -= 7
    octave, pitch = notes[index]
    # Sky cover is volume
    volume = 0
    try:
        volume = opacity_to_volume[opacity]
    except:
        pass
    return Note(pitch, octave, dur, 127)
Ejemplo n.º 30
0
def random_melody(note_list, octave_low, octave_high, dur_list):
    rm_seq = NoteSeq()  #[]
    rm_data = []
    melody_len = 0
    while melody_len < 8:  # while True if break bug
        pitch = random.choice(note_list)  #refactor by root +2 +4 ...
        octave = random.randint(octave_low, octave_high)
        dur = random.choice(dur_list)
        vol = random.randrange(80, 125, 5)  #refactor
        print([pitch, octave, dur, vol])
        rm_seq.append(Note(pitch, octave, dur, vol))  #refactor
        rm_data.append([pitch, octave, dur, vol])
        melody_len += dur
    print(melody_len)
    rm = [rm_seq, rm_data]
    return rm
Ejemplo n.º 31
0
    def test_tonal_transposition(self):
        scale = NoteSeq("C D E F G A B")

        c = Note("C")
        c_transp_fifth_up = c.tonal_transposition(5, scale)
        c_transp_second_up = c.tonal_transposition(2, scale)

        a = Note("A")
        a_transp_fourth_up = a.tonal_transposition(4, scale)
        a_transp_fifth_up = a.tonal_transposition(5, scale)

        self.assertEqual(c_transp_fifth_up, Note("G"))
        self.assertEqual(c_transp_second_up, Note("D"))
        self.assertEqual(a_transp_fourth_up, Note("D''"))
        self.assertEqual(a_transp_fifth_up, Note("E''"))
Ejemplo n.º 32
0
notes = []
for t in range(len(g)):
  chord = {}
  vol_orig = g[t].mean()
  while g[t].mean() > 0:
    note_probs = np.dot(notes_start, g[t])
    i = note_probs.argmax()
    best_match = (g[t]*notes_start[i]).argmax()
    vol = float(g[t][best_match]) / notes_start[i][best_match]
    if vol < 1e-2: break #if int(100*vol)
    if vol * g[t].mean() / vol_orig > 0.2:
      chord[i] = chord.get(i,0) + vol
    #print i,vol
    g[t] -= (vol*notes_start[i]).astype(int)
  
  for i in chord:
    if active.get(i) and chord[i] > active[i].volume:
      notes.append(active[i])
        
    if active.get(i) and chord[i] < active[i].volume:
      active[i].dur += 0.25
    
    else:
      active[i] = Note(classes[i])
      active[i].time = t
      active[i].volume = 70#max(int(min(100*chord[i], 100)),10)
  for i in set(active) - set(chord): # + those new
    notes.append(active[i])
    del active[i]    

test_output(notes)
Ejemplo n.º 33
0
 def test_stretch_dur(self):
     n1 = Note(value=4, dur=0.25, octave=3)
     n2 = n1.stretch_dur(2)
     n3 = n1.stretch_dur(0.5)
     self.assertEqual(n2.dur, 0.5)
     self.assertEqual(n3.dur, 0.125)
Ejemplo n.º 34
0
 def test_transposition_octave(self):
     e = Note(value=4, dur=0.25, octave=7)
     self.assertNotEqual(e.transposition(2), Note(value=6))
     self.assertEqual(e.transposition(2), Note(value=6, dur=0.25, octave=7))
     self.assertEqual(e.transposition(10), Note(value=2, dur=0.25, octave=8))
Ejemplo n.º 35
0
 def test_transposition(self):
     c = Note(value=0)
     self.assertEqual(c.transposition(2), Note(value=2))
     self.assertEqual(c.transposition(0), Note(value=0))
     self.assertEqual(c.transposition(11), Note(value=11))
Ejemplo n.º 36
0
def note_harmonize(self, scale, interval=3, size=3):
    i = (interval - 1)
    indices = range(1, size*i, i)
    return self.harmonize_template(scale, indices)

Note.harmonize_template = note_harmonize_template
Note.harmonize = note_harmonize

def noteseq_harmonize_template(self, indices):
    return [\
        NoteSeq(note.harmonize_template(self, indices)) for note in self\
    ]

NoteSeq.harmonize_template = noteseq_harmonize_template

c = Note("C")
assert str(c) == '<C>'
c_major_scale = NoteSeq("C D E F G A B")
assert str(c_major_scale) == '<Seq: [<C>, <D>, <E>, <F>, <G>, <A>, <B>]>'

assert str(c.harmonize(c_major_scale)) == '[<C>, <E>, <G>]'
assert str(c.harmonize_template(c_major_scale, [1, 3, 5])) == '[<C>, <E>, <G>]'

assert str(c.harmonize_template(c_major_scale, [1, 2, 3])) == '[<C>, <D>, <E>]'
assert str(c.harmonize_template(c_major_scale, [1, 4, 2])) == '[<C>, <F>, <D>]'
assert str(c.harmonize_template(c_major_scale, [5, 7, 9])) == '[<G>, <B>, <D>]'

assert str(c.harmonize_template(c_major_scale, [1, 2, 3, 4])) == \
       '[<C>, <D>, <E>, <F>]'
assert str(c.harmonize_template(c_major_scale, [1, 3, 5, 6, 8])) == \
       '[<C>, <E>, <G>, <A>, <C>]'