Skip to content

Commit

Permalink
🗋 update Readme, revert changes to core.py
Browse files Browse the repository at this point in the history
  • Loading branch information
ghalestrilo committed Jul 27, 2021
1 parent 8a281e7 commit 433ddea
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 10 deletions.
27 changes: 22 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,30 @@ The toolbox propose a set of musically informed objective measures to obtain ana
3. Note length histogram: To extract the note length histogram, we first define a set of allowable beat length classes [full, half, quarter, 8th, 16th, dot half, dot quarter, dot 8th, dot 16th, half note triplet, quarter note triplet, 8th note triplet]. The rest option, when activated, will double the vector size to represent the same lengths for rests. The classification of each event is performed by dividing the basic unit into the length of (barlength)/96, and each note length is quantized to the closest length category. The output vector has a length of either 12 or 24, respectively.
4. Note length transition matrix: Similar to the pitch class transition matrix, the note length tran- sition matrix provides useful information for rhythm description. The output feature dimension is 12 × 12 or 24 × 24, respectively.

### Dependency
### Dependencies
---
* [`scipy`](http://www.scipy.org/)
* [`numpy`](http://www.numpy.org)
* [`pretty-midi`](https://github.com/craffel/pretty-midi)
* [`python-midi`](https://github.com/vishnubob/python-midi)
* [`sklearn`](https://scikit-learn.org/stable/)
### To use
Detailed documentation included [here](https://github.com/RichardYang40148/mgeval/blob/master/mgeval/documentation.md).

Demonstration of metrics included in [demo.ipynb](https://github.com/RichardYang40148/mgeval/commits?author=RichardYang40148)
* [`pickle`](https://docs.python.org/3/library/pickle.html) (optional)

### To use
---

#### Library Reference

Detailed documentation included [here](https://github.com/RichardYang40148/mgeval/blob/master/mgeval/documentation.md).

Demonstration of metrics included in [demo.ipynb](https://github.com/RichardYang40148/mgeval/commits?author=RichardYang40148)

#### Standalone Module

You can run mgeval as a standalone module with the following command on the root directory:

```shell
python . <path/to/first/sample/directory> <path/to/second/sample/directory> <output_filename>
```

Provided both directories exist and contain valid MIDI files, this script calculates all available metrics for each set and save the result to `output_filename`, as a pickle.
11 changes: 9 additions & 2 deletions __main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
import pretty_midi
from pprint import pprint
import pickle
# import seaborn as sns
# import matplotlib.pyplot as plt
from mgeval import core, utils
from sklearn.model_selection import LeaveOneOut

Expand All @@ -30,9 +28,18 @@
set1 = glob.glob(os.path.join(args.set1dir, '*'))
set2 = glob.glob(os.path.join(args.set2dir, '*'))

print('Evaluation sets (sample and baseline):')
print(set1)
print(set2)

if not any(set1):
print("Error: sample set it empty")
exit()

if not any(set2):
print("Error: baseline set it empty")
exit()

# Initialize Evaluation Set
num_samples = min(len(set2), len(set1))

Expand Down
4 changes: 1 addition & 3 deletions mgeval/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,7 @@ def bar_pitch_class_histogram(self, feature, track_num=1, num_bar=None, bpm=120)

if actual_bar > num_bar:
mod = np.mod(len(piano_roll), bar_length*128)
piano_roll = piano_roll[:-mod]
piano_roll = piano_roll.reshape((num_bar, -1, 128)) # make exact bar
# piano_roll = piano_roll[:-np.mod(len(piano_roll), bar_length)]
piano_roll = piano_roll[:-np.mod(len(piano_roll), bar_length)].reshape((num_bar, -1, 128)) # make exact bar
elif actual_bar == num_bar:
piano_roll = piano_roll.reshape((num_bar, -1, 128))
else:
Expand Down
Binary file modified mgeval/core.pyc
Binary file not shown.

0 comments on commit 433ddea

Please sign in to comment.