Skip to content

Commit

Permalink
code syntax highlighting, example section for Vis
Browse files Browse the repository at this point in the history
  • Loading branch information
SamuelJanas committed Nov 11, 2023
1 parent fa99539 commit fbc7f27
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 0 deletions.
Binary file added docs/assets/pianoroll.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 36 additions & 0 deletions docs/examples/visualizations.md
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)
13 changes: 13 additions & 0 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,26 @@ theme:
- search.suggest
- search.highlight
- content.action.edit
- content.code.copy

nav:
- Home:
- Welcome to Fortepyan: index.md
- Documentation:
- Midi Dataclass: documentation/midi_classes.md
- Examples:
- Visualizations: examples/visualizations.md


plugins:
- search
- mkdocstrings

markdown_extensions:
- pymdownx.highlight:
anchor_linenums: true
line_spans: __span
pygments_lang_class: true
- pymdownx.inlinehilite
- pymdownx.snippets
- pymdownx.superfences

0 comments on commit fbc7f27

Please sign in to comment.