Giter Club home page Giter Club logo

tayuya's Introduction

Tayuya

Python library to generate guitar tabs from MIDI files

Installation

# Install globaly
$ pip install tayuya

# Install only for the current user
$ pip install --user tayuya

Usage

>>> from tayuya import MIDIParser
>>> mid = MIDIParser('sample.mid', track=0)
>>> print(mid.render_tabs())
E-------------14--------------------------16--14----------14--------------
A-------------------------------------------------17--17------16--17--16--
D-16------16------16--16--16--16------16----------------------------------
G-----18--------------------------18--------------------------------------
B-------------------------------------------------------------------------
E-------------------------------------------------------------------------

Don't forget to set the track argument with the appropriate track number desired.

Get track numbers of all the tracks in the MIDI file

>>> from tayuya import MIDIParser
>>> mid = MIDIParser('sample.mid', track=0)
>>> mid.get_tracks()
{0: 'Lead Guitar',
 1: 'Rhthym Guitar Dist',
 2: 'Acoustic Guitar',
 3: 'Rhthym Guitar Clean & Dist',
 4: 'Lead Guitar Fill',
 5: 'Guitar Harmonics',

Advanced

MIDI

Get all notes played in the MIDI track

>>> mid = MIDIParser('sample.mid', track=0)
>>> mid.notes_played()
[{'note': 'C#5', 'time': 18},
 {'note': 'C#5', 'time': 30},
 {'note': 'B4', 'time': 26},
 {'note': 'C5', 'time': 0},
 {'note': 'C5', 'time': 28},
 {'note': 'C#5', 'time': 28},
 {'note': 'C#5', 'time': 30}]

Get key of the track

>>> mid = MIDIParser('sample.mid', track=0)
>>> mid.get_key()

Tabs

Get all notes to play

You can use this example to generate all the notes to play with their string and fret positions.

>>> mid = MIDIParser('sample.mid', track=0)
>>> tabs = Tabs(notes=mid.notes_played(), key=mid.get_key())
>>> tabs.generate_notes(tabs.find_start())
[('C#3', 5, 4),
 ('G#3', 4, 6),
 ('C#4', 3, 6),
 ('F4', 2, 6),
 ('B2', 6, 7),
 ('D#3', 5, 6),
 ('F#3', 4, 4),
 ('B3', 3, 4),
 ('D#4', 3, 8),
 ('F#2', 6, 2)]

Each tuple here is (note, string, fret)

How it works?

Here's a brief of how it works:

  • Fetch a track from the MIDI file
  • Find all the notes played and convert from MIDI code values to music notes
  • Find a scale for the set of notes extracted
  • Find the best position to play the extracted notes using the scale detected

Limitations

  • Works only for guitar solos. Implementation for determination and rendering of chords is not done yet.
  • Works only for standard tuning (E A D G B E)

Todo

  • Render tabs using Lilypond or some GUI alternative
  • Implement logic to determine and render chords
  • Better the scale detection implementation
  • Transposing
  • Add way to handle non standard tuning
  • More stringed instruments

License

MIT

Credits

Tayuya is made possible by following open source softwares:

The name

Tayuya (たゆや)

tayuya's People

Contributors

sdushantha avatar vipul-sharma20 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

tayuya's Issues

Unable to use mid.render_tabs()

I can do the following without issues:

mid = MIDIParser(args.input_file, track=1)
#print(mid.render_tabs())
print(mid.get_tracks())
print(mid.notes_played())
print(mid.get_key())
#mid.render_tabs()

With the following output:

{0: '', 1: 'Guitar', 2: '', 3: '', 4: '', 5: '', 6: ''}
[{'note': 'F#7', 'time': 0}, {'note': 'F#7', 'time': 0}, {'note': 'A3', 'time': 0}, {'note': 'F#7', 'time': 0}, {'note': 'F#7', 'time': 0}, {'note': 'F#7', 'time': 0}, {'note': 'F3', 'time': 0}, {'note': 'F#7', 'time': 0}, {'note': 'E3', 'time': 0}, {'note': 'F#7', 'time': 0}, {'note': 'F#7', 'time': 0}, {'note': 'G3', 'time': 0}, {'note': 'F#7', 'time': 0}, {'note': 'A3', 'time': 0}, {'note': 'F#7', 'time': 0}, {'note': 'F#7', 'time': 0}, {'note': 'F#7', 'time': 0}, {'note': 'F#7', 'time': 0}, {'note': 'F#7', 'time': 0}]
(<music21.pitch.Pitch F#>, 'minor')

But, when I try to uncomment mid.render_tabs() I get the following error:

  File "/Users/cboxgo/PycharmProjects/GuitarProjects/venv/lib/python3.11/site-packages/tayuya/midi.py", line 119, in render_tabs
    to_play = tabs.generate_notes()
              ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cboxgo/PycharmProjects/GuitarProjects/venv/lib/python3.11/site-packages/tayuya/tabs.py", line 30, in generate_notes
    note_fret, note_string = self.note_nearest_to_fret(fret, note['note'], scale_notes)
                             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/cboxgo/PycharmProjects/GuitarProjects/venv/lib/python3.11/site-packages/tayuya/tabs.py", line 58, in note_nearest_to_fret
    for note_string, note_fret in note_info.items():
                                  ^^^^^^^^^
UnboundLocalError: cannot access local variable 'note_info' where it is not associated with a value

Any idea why this might be causing the failure?

TypeError: Tabs.generate_notes() takes 1 positional argument but 2 were given

environment
google colab

steps

pip install -U tayuya
from tayuya import MIDIParser, Tabs
mid = MIDIParser('sample.mid', track = 0)
tabs = Tabs(notes = mid.notes_played(), key = mid.get_key() )
tabs.generate_notes(tabs.find_start() )

result

TypeError                                 Traceback (most recent call last)
[<ipython-input-43-1eb26bcffc67>](https://localhost:8080/#) in <cell line: 1>()
----> 1 tabs.generate_notes(tabs.find_start() )

TypeError: Tabs.generate_notes() takes 1 positional argument but 2 were given

best regards

UnboundLocalError: local variable 'note_info' referenced before assignment

environment
google colab

steps

pip install -U tayuya
from tayuya import MIDIParser, Tabs
mid = MIDIParser('sample.mid', track = 0)
mid.render_tabs()

result

UnboundLocalError                         Traceback (most recent call last)
[<ipython-input-42-59341503e691>](https://localhost:8080/#) in <cell line: 1>()
----> 1 mid.render_tabs()

2 frames
[/usr/local/lib/python3.10/dist-packages/tayuya/tabs.py](https://localhost:8080/#) in note_nearest_to_fret(self, fret, note, scale_notes)
     56         min_fret = min_string = min_diff = 999
     57 
---> 58         for note_string, note_fret in note_info.items():
     59             if not note_fret:
     60                 continue

UnboundLocalError: local variable 'note_info' referenced before assignment

best regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.