Beispiel #1
0
static int
learn_button (WButton * button, int action)
{
    WDialog *d;
    char *seq;

    (void) button;

    d = create_message (D_ERROR, _("Teach me a key"),
                        _("Please press the %s\n"
                          "and then wait until this message disappears.\n\n"
                          "Then, press it again to see if OK appears\n"
                          "next to its button.\n\n"
                          "If you want to escape, press a single Escape key\n"
                          "and wait as well."), _(key_name_conv_tab[action - B_USER].longname));
    mc_refresh ();
    if (learnkeys[action - B_USER].sequence != NULL)
    {
        g_free (learnkeys[action - B_USER].sequence);
        learnkeys[action - B_USER].sequence = NULL;
    }

    seq = learn_key ();
    if (seq != NULL)
    {
        /* Esc hides the dialog and do not allow definitions of
         * regular characters
         */
        gboolean seq_ok = FALSE;

        if (*seq != '\0' && strcmp (seq, "\\e") != 0 && strcmp (seq, "\\e\\e") != 0
            && strcmp (seq, "^m") != 0 && strcmp (seq, "^i") != 0
            && (seq[1] != '\0' || *seq < ' ' || *seq > '~'))
        {
            learnchanged = TRUE;
            learnkeys[action - B_USER].sequence = seq;
            seq = convert_controls (seq);
            seq_ok = define_sequence (key_name_conv_tab[action - B_USER].code, seq, MCKEY_NOACTION);
        }

        if (!seq_ok)
            message (D_NORMAL, _("Cannot accept this key"), _("You have entered \"%s\""), seq);

        g_free (seq);
    }

    dlg_run_done (d);
    dlg_destroy (d);

    dlg_select_widget (learnkeys[action - B_USER].button);

    return 0;                   /* Do not kill learn_dlg */
}
static int learn_button (int action, void *param)
{
    unsigned char *seq;
    Dlg_head *d = message (D_INSERT | 1, _(" Teach me a key "),
_("Please press the %s\n"
"and then wait until this message disappears.\n\n"
"Then, press it again to see if OK appears\n"
"next to its button.\n\n"
"If you want to escape, press a single Escape key\n"
"and wait as well."), 
        _(key_name_conv_tab [action - B_USER].longname));
    mc_refresh ();
    if (learnkeys [action - B_USER].sequence != NULL) {
	free (learnkeys [action - B_USER].sequence);
	learnkeys [action - B_USER].sequence = NULL;
    }
    seq = learn_key ();

    if (seq){
	/* Esc hides the dialog and do not allow definitions of
	 * regular characters
	 */
	if (*seq && strcmp (seq, "\\e") && strcmp (seq, "\\e\\e")
	    && strcmp (seq, "^m" ) 
            && (seq [1] || (*seq < ' ' || *seq > '~'))){
	    
	    learnchanged = 1;
	    learnkeys [action - B_USER].sequence = seq;
	    seq = convert_controls (seq);
	    define_sequence (key_name_conv_tab [action - B_USER].code, seq, 
			     MCKEY_NOACTION);
	} else {
	    message (0, _(" Cannot accept this key "),
		_(" You have entered \"%s\""), seq);
	}
	
    	free (seq);
    }
    
    dlg_run_done (d);
    destroy_dlg (d);
    dlg_select_widget (learn_dlg, learnkeys [action - B_USER].button);
    return 0; /* Do not kill learn_dlg */
}
Beispiel #3
0
/** 
 * Prompt for learning input. Build key database.
 */
void
learn_mode ( void )
{
	int keyi;
	int i, key_offset;
	int learn_firstkey = 0;
	int learn_note = 0;
	int learn_keys = 0;

	printf( "Press the key that shall henceforth be known as EXIT\n" );

	keyi = get_key();

	map[keyi].control = CKEY_EXIT;

	printf
		( "Press each piano key in succession, beginning with the left-most. When you run out of keys, press the first one again.\n" );

	for ( ;; )
	{
		keyi = get_key();

#if 0
		ioctl( fd, KDMKTONE, ( 60 << 16 ) + 0x637 - ( learn_note * 10 ) );
#endif

		printf( "%i ", learn_note );
		fflush( stdout );

		if ( keyi == learn_firstkey )
			break;
		else if ( !learn_firstkey )
			learn_firstkey = keyi;

		map[keyi].control = 0;
		map[keyi].ev_type = SND_SEQ_EVENT_NOTE;
		map[keyi].number = learn_note++;

		learn_keys++;
	}

	printf( "\n%i keys encoded.\nNow press the key that shall be middle C.\n",
			learn_keys );

	keyi = get_key();

	key_offset = map[keyi].number;

	for ( i = 0; i < elementsof( map ); i++ )
	{
		if ( map[i].ev_type == SND_SEQ_EVENT_NOTE )
			map[i].number -= key_offset;
	}

	if ( map[keyi].number + ( 12 * octave ) != 60 )
	{
		fprintf( stderr, "Error in key logic! ( middle C == %i )\n",
				 map[keyi].number + ( 12 * octave ) );
	}

	printf
		( "Basic configuration complete. Press EXIT if you'd like to stop learning now, or any other key if you'd like to continue and configure the auxilliary input methods.\n" );

	keyi = get_key();

	if ( map[keyi].control == CKEY_EXIT )
		return;

	printf
		( "If your device has 18 key control pad, and you would like to program it now, press any key. To skip this step (and move on to pedals/footswitches), press EXIT.\n" );

	keyi = get_key();

	if ( map[keyi].control != CKEY_EXIT )
	{
		printf( "Press buttons 0 through 9 in ascending numerical order.\n" );

		for ( i = 0; i < 10; i++ )
		{
			keyi = get_key();

			printf( "%i encoded. ", i );
			fflush( stdout );

			map[keyi].control = CKEY_NUMERIC;
			map[keyi].number = i;
		}

		for ( i = CKEY_MIN + 1; i <= CKEY_MAX; i++ )
			learn_key( i );
	}

	printf( "Press and release the Sustain Pedal.\n" );

	keyi = get_key();

	map[keyi].ev_type = SND_SEQ_EVENT_CONTROLLER;
	map[keyi].number = 64;

	printf( "Press and release the Portamento Pedal.\n" );

	keyi = get_key();

	map[keyi].ev_type = SND_SEQ_EVENT_CONTROLLER;
	map[keyi].number = 65;

	printf( "Press and release the Soft Pedal.\n" );

	keyi = get_key();

	map[keyi].ev_type = SND_SEQ_EVENT_CONTROLLER;
	map[keyi].number = 67;

	printf( "\nLearning Complete!\n" );
}