<commit_before>
## Original code (pygame example): https://bitbucket.org/pygame/pygame/src/25e3f2cee879/examples/midi.py
# Is also found in the local installation at Python27/Lib/site-packages/pygame/examples/midi.py

import pygame
from pygame import midi
import time, sys

def main():
    pass
    

pygame.init()
midi.init()

print "Devices:", midi.get_count()
out_device = midi.get_default_output_id()

print "Uses:", out_device

output = midi.Output( out_device )

GRAND_PIANO = 0
CHURCH_ORGAN = 19

try:
    output.set_instrument( CHURCH_ORGAN )
    output.note_on( 64, 100 )
    time.sleep( 1 )
    output.note_off( 64, 0 )
finally:
    del output
    midi.quit()<commit_msg>Works quite well now. Once understanding the library, the programming was really simple<commit_after>
## Original code (pygame example): https://bitbucket.org/pygame/pygame/src/25e3f2cee879/examples/midi.py
# Is also found in the local installation at Python27/Lib/site-packages/pygame/examples/midi.py

import pygame
from pygame import midi
import time, sys

def init_keyboard(start_note):
    keyboard = {}
    
    from pygame.locals import *
    keys = [K_TAB, K_1, K_q, K_2, K_w, K_3, K_e,
            K_r, K_5, K_t, K_6, K_y, K_u, K_8, K_i, K_9, K_o, K_0, K_p]
    
    i = start_note
    for k in keys:
        keyboard[k] = i
        i = i+1
    return keyboard

pygame.init()
midi.init()

print "Devices:", midi.get_count()
out_device = midi.get_default_output_id()

print "Uses:", out_device

## Global variables
output = midi.Output( out_device )
keyboard = init_keyboard(53)

# Instruments at http://www.skoogmusic.com/manual/manual1.1/Skoog-Window/navigation/MIDI-Tab/index
GRAND_PIANO = 0
CHURCH_ORGAN = 19
STEEL_GUITAR_AUCOUSTIC = 25

try:
    output.set_instrument( STEEL_GUITAR_AUCOUSTIC )
    
    
    screen = pygame.display.set_mode([250,80])
    screen.fill((0,0,0))
    pygame.display.set_caption("MIDI Keyboard")
    pygame.display.flip()
    
    octave = 0
    
    while 1:
        e = pygame.event.wait()
        if e.type == pygame.QUIT:
            break
        elif e.type == pygame.KEYDOWN:
            if e.key == pygame.K_ESCAPE:
                break
            elif e.key == pygame.K_z:
                octave = octave - 1
            elif e.key == pygame.K_x:
                octave = octave + 1
            else:
                try:
                    note = keyboard[e.key]
                    output.note_on(note + 12*octave, 100)
                except KeyError:
                    pass
        elif e.type == pygame.KEYUP:
            try:
                note = keyboard[e.key]
                output.note_off(note + 12*octave, 0)
            except KeyError:
                pass
    
finally:
    del output
    midi.quit()
{'fraction_non_alphanumeric': 0.10530137981118373, 'fraction_numerical': 0.024691358024691357, 'mean_word_length': 2.291517323775388, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 1, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7020798', 'n_tokens_mistral': 1048, 'n_tokens_neox': 978, 'n_words': 222}