Comments (9)
I got something reasonable by putting that code in a notebook and adding a new cell with this (using some other piano-based audio files):
from jchord.progressions import ChordProgression
from jchord.chords import ChordWithRoot, InvalidChord
chord_objects = []
durations = []
for start, stop, name in chords:
name = name.replace(":", "")
try:
chord = ChordWithRoot.from_name(name)
except InvalidChord:
chord = ChordProgression.DUMMY_CHORD
chord_objects.append(chord)
durations.append(stop - start)
ChordProgression(chord_objects).to_midi("out.mid", beats_per_chord=durations)
from jchord.
This can be done by creating a ChordProgression
object and calling its to_midi()
method. You need to handle the case where the library doesn't understand the input string by catching the InvalidChord
exception.
There is some example code in this unit test (requires jchord version 0.2.1): https://github.com/jonathangjertsen/jchord/blob/f3a63c949118e9261b761a5145073d12593be006/test/test_5_issues.py In your case the beats_per_chord
list would be the differences between consecutive curr_beat
values.
What did you use to extract the chords from audio? Depending on what kind of data it returns, it could be more efficient to use mido directly.
from jchord.
Thank you for your example. I used MADMOM for extracting the chords. I think I have to individually change the chord names. Anything else you recommend?
from jchord.
From looking at the documentation for that library, it seems like you could combine the note processor https://madmom.readthedocs.io/en/latest/modules/features/notes.html with the midi utilities https://madmom.readthedocs.io/en/latest/modules/io/midi.html to do the audio-to-midi conversion.
from jchord.
Yes, exactly. Unfortunately, their chord notations are different than jchord.
from jchord.
What I was thinking is that it could be possible to just pass the output of the RNNPianoNoteProcessor/NotePeakPickingProcessor into the MIDIFile.from_notes(...)
function in madmom.
That said, the only difference seems to be that madmom adds a :
between the root note and the chord quality. So in your image, prev_chord.replace(":", "")
should return something that jchord recognizes.
from jchord.
May be.. I will check that.
I can share you my code,
from madmom.features import CNNChordFeatureProcessor, CRFChordRecognitionProcessor, RNNDownBeatProcessor, DBNDownBeatTrackingProcessor
audio_file_name = "/content/Ride.mp3"
chord_processor = CNNChordFeatureProcessor()
chord_decoder = CRFChordRecognitionProcessor()
chords = chord_decoder(chord_processor(audio_file_name))
beat_processor = RNNDownBeatProcessor()
beat_decoder = DBNDownBeatTrackingProcessor(beats_per_bar=[4], fps=100)
beats = beat_decoder(beat_processor(audio_file_name))
chord_idx = 0
for beat_idx in range(len(beats) - 1):
curr_beat_time, curr_beat = beats[beat_idx]
# visually separate measures
if int(curr_beat) == 1:
print()
# find the corresponding chord for this beat
while chord_idx < len(chords):
chord_time, _ , _= chords[chord_idx]
prev_beat_time, _ = (0, 0) if beat_idx == 0 else beats[beat_idx - 1]
eps = (curr_beat_time - prev_beat_time) / 2
if chord_time > curr_beat_time + eps:
break
chord_idx += 1
# print beat and chord info
_, _, prev_chord = chords[chord_idx - 1]
print(curr_beat_time, curr_beat, prev_chord)
from jchord.
That works perfectly. But did you notice a delay(may be half beat) in your case?
Too many experiments with code. sorry about that. See the bottom.
It seems okay if I use strings. But not with piano. It's with the chord recognition code.
Thank you for all your help.. Happy new year.
from jchord.
The main issue here seems to be solved, created #71 for the issue with delay in generated midi files
from jchord.
Related Issues (20)
- Make it easier to divide bars
- Songs
- Robust reading of chord progressions from midi files HOT 1
- Move doc_gen to separate library HOT 2
- Question marks(???) on detected chords HOT 5
- Any function to convert a audio to midi ? HOT 2
- Write notes to midi HOT 1
- Dependabot couldn't authenticate with https://pypi.python.org/simple/
- Root note when using ChordProgression.from_string() HOT 7
- Arpeggios/string instruments HOT 4
- Small delay at the start of generated MIDI files
- Overhaul documentation, usability, examples and recipes HOT 1
- Test coverage for robust reading of chord progressions from midi files
- Empty cell at the end of a row in XLSX is probably not treated as a repetition
- Allow install with optional dependencies (`pip install jchord[midi]`, `pip install jchord[midi, xlsx]` etc)
- Switch to Github Actions
- Add property-based tests
- MusicXML in/out
- test
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 jchord.