From 02d896c4ae006581b0c0395d6f05516d663b8abe Mon Sep 17 00:00:00 2001 From: ark1ee Date: Fri, 24 Dec 2021 18:18:26 +0800 Subject: [PATCH 1/4] add VELOCITY_DICT and offset in Clip --- musing/musing.py | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/musing/musing.py b/musing/musing.py index d5ea24a..15a72e9 100644 --- a/musing/musing.py +++ b/musing/musing.py @@ -17,8 +17,18 @@ 'dim7', 'maj7', 'aug7', 'sus2', 'sus4'] MINUTE = 60.00000 DEFAULT_MIDI_FILE = 'midi_data/40126.mid' +STRONG = 36 +SUB_STRONG = 27 +WEAK = 18 DEFAULT_VELOCITY = 36 - +VELOCITY_DICT = { + 1:[36], + 2:[36,18], + 3:[36,18,18], + 4:[36,18,27,18], + 5:[36,18,27,18,18], + 6:[36,18,18,27,18,18], +} class Musing(object): ''' @@ -349,7 +359,10 @@ class Clip(object): last_time = 0.0 - def __init__(self, rhythms=False, notes=False, velocity_list=[], start_time=.0): + def init_last_time(self,start = 0.0): + self.last_time = start + + def __init__(self, rhythms=False, notes=False, velocity_list=[], start_time=.0, default_velocity=True,offset=0): self.midi = Musing() @@ -367,7 +380,7 @@ def __init__(self, rhythms=False, notes=False, velocity_list=[], start_time=.0): for rhythm, note in zip(rhythms, notes): note = pretty_midi.Note( - velocity=DEFAULT_VELOCITY, pitch=pretty_midi.note_name_to_number(note), start=start_time + rhythm[0], end=start_time + rhythm[1]) + velocity=rhythm[2] if default_velocity else DEFAULT_VELOCITY, pitch=pretty_midi.note_name_to_number(note)-offset, start=start_time + rhythm[0], end=start_time + rhythm[1]) self.note_list.append(note) def add_notes(self, notes=False, start_time=.0): @@ -396,10 +409,9 @@ def add_column_chords(self,note_list,beat_time=1.0,p='5'): if isinstance(note_list,basestring): note_list = Musing.parse_chord(note_list) - + print(note_list) for note in note_list: - - self.note_list.append(pretty_midi.Note( velocity=DEFAULT_VELOCITY, pitch=pretty_midi.note_name_to_number("%s%s" % (note,p)), start= self.last_time, end=self.last_time + beat_time)) + self.note_list.append(pretty_midi.Note( velocity=SUB_STRONG, pitch=pretty_midi.note_name_to_number("%s%s" % (note,p)), start= self.last_time, end=self.last_time + beat_time)) elif isinstance(note_list,list): @@ -468,6 +480,7 @@ def __repr__(self): def __iter__(self): return self.time_list.__iter__() + def __len__(self): return len(self.time_list) @@ -498,13 +511,13 @@ def parse_rhythm_bar(self, rhythm_bar, now_time, unit_time=.5): s_list = [] unit = unit_time / float(t) - - for r in r_list: + + for index,r in enumerate(r_list): if '-' in r: start_time = now_time[0] last_time = len(r) * unit - m_list.append((start_time, last_time + start_time)) + m_list.append((start_time, last_time + start_time,VELOCITY_DICT.get(t,[27,27,27,27,27,27,27,27,27])[index])) now_time[0] += last_time elif '.' in r: start_time = now_time[0] From 4cd3e5400e028f16bef27ede580d0cb60a5b50c1 Mon Sep 17 00:00:00 2001 From: ark1ee Date: Fri, 24 Dec 2021 18:35:39 +0800 Subject: [PATCH 2/4] Create daobei.py --- daobei.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 daobei.py diff --git a/daobei.py b/daobei.py new file mode 100644 index 0000000..2e55070 --- /dev/null +++ b/daobei.py @@ -0,0 +1,19 @@ +from musing import MusingRhythm,Clip +r = '.. - -|--- -|- - - -|-- - -|-- - -|- - - -|-' +mr = MusingRhythm(r,unit_time=1.8) +m = ['G5','B5',\ +'C6','E6' , \ +'F6','G6','B6','C7', +'G6','B6','C7',\ +'F6','E6','F6', \ +'D6','C6','B5','D6',\ +'C6'] +# 3 + +# for i in range(1,7): +# Clip(mr,m,offset=i).play() +# c = Clip(mr,m,offset=3) +c = Clip(mr,m) +c.init_last_time(start = 0.9) +c.add_column_chords("G5M",beat_time=3) +c.play() From dc3ad0b788479aa0b99d32abdf753710aaf2ba19 Mon Sep 17 00:00:00 2001 From: ark1ee Date: Fri, 24 Dec 2021 18:59:57 +0800 Subject: [PATCH 3/4] Update musing.py --- musing/musing.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/musing/musing.py b/musing/musing.py index 15a72e9..77e770b 100644 --- a/musing/musing.py +++ b/musing/musing.py @@ -404,14 +404,14 @@ def play(self): def last(self,time): self.last_time += time - def add_column_chords(self,note_list,beat_time=1.0,p='5'): + def add_column_chords(self,note_list,beat_time=1.0,p='5',velocity=SUB_STRONG,repeat=2): if isinstance(note_list,basestring): note_list = Musing.parse_chord(note_list) - print(note_list) - for note in note_list: - self.note_list.append(pretty_midi.Note( velocity=SUB_STRONG, pitch=pretty_midi.note_name_to_number("%s%s" % (note,p)), start= self.last_time, end=self.last_time + beat_time)) + for repeat_div in range(0,repeat): + for note in note_list: + self.note_list.append(pretty_midi.Note( velocity=velocity-3*repeat_div, pitch=pretty_midi.note_name_to_number("%s%s" % (note,p)), start= self.last_time+beat_time/float(repeat)*repeat_div, end=self.last_time + beat_time/float(repeat)*repeat_div)) elif isinstance(note_list,list): From db23b8670831f244c4b3182ce89be0e420e58825 Mon Sep 17 00:00:00 2001 From: ark1ee Date: Fri, 24 Dec 2021 19:03:42 +0800 Subject: [PATCH 4/4] ADD chord progress --- daobei.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/daobei.py b/daobei.py index 2e55070..335e9c7 100644 --- a/daobei.py +++ b/daobei.py @@ -15,5 +15,11 @@ # c = Clip(mr,m,offset=3) c = Clip(mr,m) c.init_last_time(start = 0.9) -c.add_column_chords("G5M",beat_time=3) +c.add_column_chords("G4M",beat_time=1.8,velocity=15) +c.add_column_chords("C5M",beat_time=1.8,velocity=15) +c.add_column_chords("F5M",beat_time=1.8,velocity=15) +c.add_column_chords("G5M",beat_time=1.8,velocity=15) +c.add_column_chords("F5M",beat_time=1.8,velocity=15) +c.add_column_chords("D5M",beat_time=1.8,velocity=15) +c.add_column_chords("C5M",beat_time=1.8,velocity=15) c.play()