Comments (3)
I try to write a function for it, but I do not know is it right :
def write_midi(words, path_outfile, word2event):
class_keys = word2event.keys()
midi_obj = miditoolkit.midi.parser.MidiFile()
# global tempo
midi_obj.tempo_changes.append(TempoChange(tempo=119, time=0))
bar_cnt = 0
all_notes = []
for i in range(len(words)):
vals = []
for kidx, key in enumerate(class_keys):
vals.append(word2event[key][words[i][kidx]])
# print(vals)
if vals[0].split(' ')[-1] == 'New':
bar_cnt += 1
if (vals[0].split(' ')[-1] == 'New') or (vals[0].split(' ')[-1] == 'Continue'):
position_ = vals[1].split(' ')[-1]
if position_ != "<PAD>" and position_ != "<MASK>":
position = int(position_.split('/')[0]) - 1
else:
continue
duration_ = vals[3].split(' ')[-1]
if duration_ != "<PAD>" and duration_ != "<MASK>":
duration = int(duration_) * 60
if duration == 0:
duration = 60
else:
continue
pitch_ = vals[2].split(' ')[-1]
if pitch_ != "<PAD>" and pitch_ != "<MASK>":
pitch = int(pitch_)
else:
continue
st = bar_cnt * BAR_RESOL + position * TICK_RESOL
et = st + duration
all_notes.append(miditoolkit.Note(velocity=60 pitch=pitch, start=st, end=et))
# save midi
piano_track = Instrument(0, is_drum=False, name='piano')
piano_track.notes = all_notes
midi_obj.instruments = [piano_track]
midi_obj.dump(path_outfile)
the velocity is set to default 60
from midi-bert.
Hi sorry for the late reply. Are you using version 1 (midi-score) or version 2 (midi-performance)?
For version 1, please refer to this code. It extracts melody MIDI given original MIDI, and you can adjust it to suit your needs.
If it's version 2, I have not pushed the code yet, and I'll try to update it this week.
I didn't run your code above, but it looks fine. If you can preprocess your generated midi to the same CP, then it should be alright!
from midi-bert.
Is the duration value multiplied by 60 and then output? In this case, the maximum duration will reach 3600, is it too long?
from midi-bert.
Related Issues (11)
- How do I get the melody data of the dataset? HOT 6
- Install with Python3.11 HOT 1
- How to extend Velocity characters ? HOT 1
- Classical Piano Compositions HOT 1
- Inference HOT 2
- make midi file from wav fomat HOT 3
- torch.nn.modules.module.ModuleAttributeError: 'TokenClassification' object has no attribute 'module' HOT 2
- About the dataset. HOT 2
- about preprocess my own pretrain data HOT 7
- melody extraction gets empty output HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from midi-bert.