libgtkmusic is a GTK+ library that provides widgets for displaying and
interacting with musical instruments views, as well as some utility
functions. It can be used for any kind of application that needs a
musical instrument view, such as virtual guitars, note detector, guitar
training and games). Currently it supports a highly customizable guitar
and a piano.
Append these lines to your ~/.profile to make it permanent.
Provided that you've successfully installed the library and its GObject
Introspection typelib, try out this minimal Python example:
#!/usr/bin/env python3importgigi.require_version('Gtk','3.0')gi.require_version('Gdk','3.0')gi.require_version('GtkMusic','0.4')fromgi.repositoryimportGtk,Gdk,GtkMusicdefnote_pressed(widget,event,midi_code):print('You pressed the note with MIDI code %d!'%midi_code)win=Gtk.Window()piano=GtkMusic.Piano()piano.add_events(Gdk.EventMask.BUTTON_PRESS_MASK)piano.connect('note_pressed',note_pressed)win.connect('destroy',Gtk.main_quit)win.add(piano)win.show_all()Gtk.main()