-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
code syntax highlighting, example section for Vis
- Loading branch information
1 parent
fa99539
commit fbc7f27
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# Example usage of Fortepyan | ||
|
||
As a first example, we will create a random midi piece and display it as a piano roll. | ||
|
||
``` py title="Getting started" | ||
import pandas as pd | ||
import numpy as np | ||
|
||
import fortepyan as ff | ||
|
||
from matplotlib import pyplot as plt | ||
from fortepyan.view.pianoroll.main import draw_pianoroll_with_velocities | ||
|
||
np.random.seed(42) # Fix the seed for reproducibility | ||
|
||
# Create a dataframe with random values | ||
random_df = pd.DataFrame( | ||
{ | ||
"start": [i for i in range(0, 100)], | ||
"duration": [np.random.uniform(0.5, 1.5) for i in range(0, 100)], | ||
"pitch": [np.random.randint(45, 90) for i in range(0, 100)], | ||
"velocity": [np.random.randint(45, 90) for i in range(0, 100)], | ||
} | ||
) | ||
random_midi = ff.MidiPiece(random_df) # Create a MidiPiece object | ||
|
||
# Let's assume we're interested in notes 5-24 | ||
interesting_part = random_midi.trim(5, 24, slice_type="index") | ||
fig = draw_pianoroll_with_velocities(interesting_part) | ||
|
||
plt.show() | ||
|
||
``` | ||
|
||
The outcome you should expect is: | ||
![Piano roll](../assets/pianoroll.png) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters