Allegro.cc - Online Community

Allegro.cc Forums » Allegro Development » Alllegro 4.2.0 beta 2 has been released!

This thread is locked; no one can reply to it. rss feed Print
Alllegro 4.2.0 beta 2 has been released!
Peter Hull
Member #1,136
March 2001

This probably happened ages ago and has been discussed, but:
When did the numeric values assigned to the KEY_* constants change?
It looks to me like the modifier keys have changed, is this correct?

This would break any program with user-defined keys that are stored as ints in a config file. Can anyone recommend the best way to

  • Handle the transition from 4.0 to 4.2

  • Make sure this doesn't happen again if the constants are changed again

NB this isn't a rant, I just wonder what's the best way to deal with this?

Pete

Elias
Member #358
May 2000

For the transition: Either convert the keys, or invalidate old configurations when compiled with 4.2.0.

If you are interested, the problem was, that the key values were ordered like:

normal keys .. modifier keys

So every time a new key was added, all modifier key values increased by one. Right now, the limit of 128 keys is hit - so probably in the compatibility layer, the values won't change anymore (but we'll have to find a way to support more keys, 128 is not enough for many keyboards).

Generally, directly using internal values like the KEY_* values isn't a good idea. But in this case, I guess it is quite safe.. the compatibility layer can't get more than 128 keys, and in 4.3.x I hope we'll simply have an int for every key, so there also will be no need to ever change the values.

--
"Either help out or stop whining" - Evert

Daniel Schlyder
Member #257
April 2000
avatar

Quote:

Make sure this doesn't happen again if the constants are changed again

Create a key macro to string map and store strings in the config file.
Below is mine. Not useful to you as-is, but editing it might take less time than typing it all in yourself. IIRC, there might also be one in one of Allegro's examples.

1key::id_name_pair const key::s_id_name_pairs[] = {
2 { KEY_A, "A", "", "" },
3 { KEY_B, "B", "", "" },
4 { KEY_C, "C", "", "" },
5 { KEY_D, "D", "", "" },
6 { KEY_E, "E", "", "" },
7 { KEY_F, "F", "", "" },
8 { KEY_G, "G", "", "" },
9 { KEY_H, "H", "", "" },
10 { KEY_I, "I", "", "" },
11 { KEY_J, "J", "", "" },
12 { KEY_K, "K", "", "" },
13 { KEY_L, "L", "", "" },
14 { KEY_M, "M", "", "" },
15 { KEY_N, "N", "", "" },
16 { KEY_O, "O", "", "" },
17 { KEY_P, "P", "", "" },
18 { KEY_Q, "Q", "", "" },
19 { KEY_R, "R", "", "" },
20 { KEY_S, "S", "", "" },
21 { KEY_T, "T", "", "" },
22 { KEY_U, "U", "", "" },
23 { KEY_V, "V", "", "" },
24 { KEY_W, "W", "", "" },
25 { KEY_X, "X", "", "" },
26 { KEY_Y, "Y", "", "" },
27 { KEY_Z, "Z", "", "" },
28 { KEY_0, "0", "", "" },
29 { KEY_1, "1", "", "" },
30 { KEY_2, "2", "", "" },
31 { KEY_3, "3", "", "" },
32 { KEY_4, "4", "", "" },
33 { KEY_5, "5", "", "" },
34 { KEY_6, "6", "", "" },
35 { KEY_7, "7", "", "" },
36 { KEY_8, "8", "", "" },
37 { KEY_9, "9", "", "" },
38 { KEY_0_PAD, "NumPad 0", "NumPad0", "Num0" },
39 { KEY_1_PAD, "NumPad 1", "NumPad1", "Num1" },
40 { KEY_2_PAD, "NumPad 2", "NumPad2", "Num2" },
41 { KEY_3_PAD, "NumPad 3", "NumPad3", "Num3" },
42 { KEY_4_PAD, "NumPad 4", "NumPad4", "Num4" },
43 { KEY_5_PAD, "NumPad 5", "NumPad5", "Num5" },
44 { KEY_6_PAD, "NumPad 6", "NumPad6", "Num6" },
45 { KEY_7_PAD, "NumPad 7", "NumPad7", "Num7" },
46 { KEY_8_PAD, "NumPad 8", "NumPad8", "Num8" },
47 { KEY_9_PAD, "NumPad 9", "NumPad9", "Num9" },
48 { KEY_F1, "F1", "", "" },
49 { KEY_F2, "F2", "", "" },
50 { KEY_F3, "F3", "", "" },
51 { KEY_F4, "F4", "", "" },
52 { KEY_F5, "F5", "", "" },
53 { KEY_F6, "F6", "", "" },
54 { KEY_F7, "F7", "", "" },
55 { KEY_F8, "F8", "", "" },
56 { KEY_F9, "F9", "", "" },
57 { KEY_F10, "F10", "", "" },
58 { KEY_F11, "F11", "", "" },
59 { KEY_F12, "F12", "", "" },
60 { KEY_ESC, "Escape", "", "" },
61 { KEY_TILDE, "Tilde", "", "" },
62 { KEY_MINUS, "Minus", "", "" },
63 { KEY_EQUALS, "Equals", "", "" },
64 { KEY_BACKSPACE, "Backspace", "", "Bckspace" },
65 { KEY_TAB, "Tab", "", "" },
66 { KEY_OPENBRACE, "Open Brace", "OpenBrace", "OBrace" },
67 { KEY_CLOSEBRACE, "Close Brace", "CloseBrace", "CBrace" },
68 { KEY_ENTER, "Return", "", "" },
69 { KEY_COLON, "Colon", "", "" },
70 { KEY_QUOTE, "Quote", "", "" },
71 { KEY_BACKSLASH, "Backslash", "", "Bckslash" },
72 { KEY_BACKSLASH2, "Backslash2", "", "Bckslsh2" },
73 { KEY_COMMA, "Comma", "", "" },
74 { KEY_STOP, "Period", "", "" },
75 { KEY_SLASH, "Slash", "", "" },
76 { KEY_SPACE, "Space", "", "" },
77 { KEY_INSERT, "Insert", "", "" },
78 { KEY_DEL, "Delete", "", "" },
79 { KEY_HOME, "Home", "", "" },
80 { KEY_END, "End", "", "" },
81 { KEY_PGUP, "Page Up", "PageUp", "" },
82 { KEY_PGDN, "Page Down", "PageDown", "" },
83 { KEY_LEFT, "Left Arrow", "LeftArrow", "Left" },
84 { KEY_RIGHT, "Right Arrow", "RightArrow", "Right" },
85 { KEY_UP, "Up Arrow", "UpArrow", "Up" },
86 { KEY_DOWN, "Down Arrow", "DownArrow", "Down" },
87 { KEY_SLASH_PAD, "NumPad Slash", "NumPadSlash", "NumSlash" },
88 { KEY_ASTERISK, "NumPad Star", "NumPadStar", "NumStar" },
89 { KEY_MINUS_PAD, "NumPad Minus", "NumPadMinus", "NumMinus" },
90 { KEY_PLUS_PAD, "NumPad Plus", "NumPadPlus", "NumPlus" },
91 { KEY_DEL_PAD, "NumPad Decimal", "NumPadDecimal", "NumDecim" },
92 { KEY_ENTER_PAD, "Enter", "", "" },
93 { KEY_PRTSCR, "Print Screen", "PrintScreen", "PrntScrn" },
94 { KEY_PAUSE, "Pause", "", "" },
95 { KEY_ABNT_C1, "ABNT_C1", "", "" },
96 { KEY_YEN, "Yen", "", "" },
97 { KEY_KANA, "Kana", "", "" },
98 { KEY_CONVERT, "Convert", "", "" },
99 { KEY_NOCONVERT, "Noconvert", "", "Noconvrt" },
100 { KEY_AT, "At", "", "" },
101 { KEY_CIRCUMFLEX, "Circumflex", "", "Circmflx" },
102 { KEY_COLON2, "Colon2", "", "" },
103 { KEY_KANJI, "Kanji", "", "" },
104 { KEY_LSHIFT, "Left Shift", "LeftShift", "LShift" },
105 { KEY_RSHIFT, "Right Shift", "RightShift", "RShift" },
106 { KEY_LCONTROL, "Left Control", "LeftControl", "LCtrl" },
107 { KEY_RCONTROL, "Right Control", "RightControl", "RCtrl" },
108 { KEY_ALT, "Alt", "", "" },
109 { KEY_ALTGR, "Alt Ground", "AltGround", "AltGr" },
110 { KEY_LWIN, "Left Windows", "LeftWindows", "LWin" },
111 { KEY_RWIN, "Right Windows", "RightWindows", "RWin" },
112 { KEY_MENU, "Menu", "", "" },
113 { KEY_SCRLOCK, "Scroll Lock", "ScrollLock", "ScrLock" },
114 { KEY_NUMLOCK, "NumLock", "", "" },
115 { KEY_CAPSLOCK, "CapsLock", "", "" },
116 { KEY_EQUALS_PAD, "NumPad Equals", "NumPadEquals", "NumEq" },
117 { KEY_BACKQUOTE, "Backquote", "", "Bckquote" },
118 { KEY_SEMICOLON, "Semicolon", "", "Semicol" },
119 { KEY_COMMAND, "Command", "", "" }
120};

Peter Hull
Member #1,136
March 2001

Well there's a function scancode_to_name for that... pity it wasn't in 4.0 :(

Pete

Daniel Schlyder
Member #257
April 2000
avatar

Yeah, hmm, I guess it's a recent addition.

Carrus85
Member #2,633
August 2002
avatar

Well, I think I might have another bug for y'all to chew on...

<edit>
Os: Windows XP SP2
AMD Athlon 64 3400+
SoundMax Integrated Audio ( comes on NForce 3 mobo's )
GeForce 440 Go 64MB
768MB Ram
</edit>

I've been doing some research into the weird minimizing bug that I have been having with the setup program, and I have been able to reproduce a bug similar to it with the following test program (not the exact same error, but it brings about some interesting results)...

test.c:

1#include <allegro.h>
2 
3int main ( int argc, char **argv )
4{
5 int voices = 0;
6 allegro_init();
7 install_keyboard ( );
8 voices = detect_digi_driver ( DIGI_AUTODETECT );
9 printf (" MIDI Testing Program\n" );
10 /* Test Variables */
11
12 MIDI *testMidi;
13
14 if ( !voices )
15 {
16 printf ( " MIDI: No voices detected! Terminating! %s\n", allegro_error);
17 }
18 else if ( voices == 0xFFFF )
19 {
20 printf ( " MIDI: Driver Detected, but no way to determine voices\n" );
21 }
22 else if ( voices == -1 )
23 {
24 printf ( " MIDI: Driver Detected, voice stealing from DIGI Driver\n" );
25 }
26 else
27 {
28 printf ( " MIDI: Driver Detected! Voices = %d\n" , voices );
29 }
30 voices = 0;
31 voices = detect_digi_driver ( DIGI_AUTODETECT );
32
33 if ( !voices )
34 {
35 printf ( " DIGI: No Hardware Detected %s\n", allegro_error );
36 }
37 else
38 {
39 printf ( " DIGI: Digital Device Detected, Voices = %d\n", voices );
40 }
41
42 if ( install_sound (DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) < 0 )
43 {
44 printf ( " Failure to initialize sound with MIDI. Error: %s\n", allegro_error );
45 return 0;
46 }
47 else
48 {
49 printf ( " Everything installed fine, I'm lost...\n");
50 }
51
52 testMidi = load_midi ( "Zelda2lc.mid" ); // got this midi file off of vgmusic.com
53 if ( play_midi ( testMidi, 0 ) != 0 )
54 {
55 printf ( " Failure to load midi file Zelda2lc.mid: %s\n", allegro_error );
56 if ( testMidi != NULL ) destroy_midi ( testMidi );
57 return 0;
58 }
59 else
60 printf ( " The Midi Loaded fine, do you hear anything? I'm guessing not\n" );
61
62
63 while ( !key[KEY_ESC] );
64 destroy_midi ( testMidi );
65 return 0;
66} END_OF_MAIN()

The code above is built with this command, FYI: gcc -o test.exe test.c -lalleg

Now, on my system, it outputs the following...

 MIDI Testing Program
 MIDI: Driver Detected, but no way to determine voices
 DIGI: Digital Device Detected, Voices = 65535
 Everything installed fine, I'm lost...
 The Midi Loaded fine, do you hear anything? I'm guessing not

..and then waits for the escape key ( expected ).

However, this is where the "interesting" results come in. Here is what I have noticed. The allegro application creates what is basically a "null" window on the task bar and assigns focus to it (this, I assume, has something to do with grabbing keypresses or something). However, whenever the null window is in focus, the MIDI will not play. If any other window is in focus, the midi does play, which presents us with an interesting problem.

I'm not sure how to further proceed debugging this problem. I can debug my own programs just fine, but a library I'm not exactly sure how to proceed with debugging.

Any ideas?

Also, some other people might want to test this just to make sure I'm not going crazy or that it is just some increadibly wacko hardware problem or something. ::)

Elias
Member #358
May 2000

Does the same happen if you call set_gfx_mode somewhere at the beginning?

--
"Either help out or stop whining" - Evert

Carrus85
Member #2,633
August 2002
avatar

I dunno, let me try that real quick... I will edit with the results.

EDIT:

It actually works even less with set_gfx_mode ( GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) added right below the voices = detect_digi_driver line.

The Midi stutters now... if you switch focus from the window to the dos window back and forth, you get what sounds like a "frame" of the midi at a time, instead of having the midi playing continuously (well, in fact it may be playing continuously, we can only hear something when we switch back and forth).

Elias
Member #358
May 2000

Ok. What if you add: set_display_switch_mode(SWITCH_BACKGROUND) after set_gfx_mode?

--
"Either help out or stop whining" - Evert

Carrus85
Member #2,633
August 2002
avatar

Adding set_display_switch_mode makes it revert back to the previous symptoms (if main window is in focus, no midi. Midi everywhere else).

Elias
Member #358
May 2000

Hm, I'm in linux right now.. so can't do much testing myself.. but I have one more thing to let you try :): Does the same also happen in exmidi (replace GFX_AUTODETECT with GFX_AUTODETECT_WINDOWED)?

--
"Either help out or stop whining" - Evert

Carrus85
Member #2,633
August 2002
avatar

Changing it to GFX_AUTODETECT_WINDOWED causes the stuttering effect.
Adding set_display_switch_mode ( SWITCH_BACKGROUND ) causes the suttering to disappear. Interesing, though, is that the counter on the inside of the window continues to count in both situations (meaning that when the window has focus, it is probably trying to play notes but can't).

Either method ( switch background and default switching mode (no switch line)) with GFX_AUTODETECT (fullscreen mode) fails to produce any midi output.

gnolam
Member #2,030
March 2002
avatar

Carrus85 said:

voices = detect_digi_driver ( MIDI_AUTODETECT );

Uhm... shouldn't that be either DIGI_AUTODETECT or detect_midi_driver?

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

Elias
Member #358
May 2000

Thanks. I can just try it with exmidi then when I'm in windows the next time. Oh, which driver was being used?

To me it sounds that somehow Allegro blocks the windows midi player from playing.. now how it does that, I have no idea. Maybe when DX Sound is initialized, there is a flag to let the midi play? Or maybe DX can itself play midi..

--
"Either help out or stop whining" - Evert

Carrus85
Member #2,633
August 2002
avatar

gnolam, you are right. However, it still does the same thing... (I'm guessing the #define is the same value for both midi and digi autodetect)

I edited the code post to reflect this.

Ron Ofir
Member #2,357
May 2002
avatar

Huh? You are still calling detect_digi_driver(DIGI_AUTODETECT) twice.

Steve Apostol
Member #4,127
December 2003

I believe the docs said that the set_gfx_mode() should go before the install_keyboard() etc. otherwise these might fail in some platforms. Have you tried that?

Carrus85
Member #2,633
August 2002
avatar

AHHH!!! Attack of TEH TYPOS!!!!

I'll try fixing it right now...

EDIT: See code two posts below for current test case code

GHA! Somedays even I wonder what I was smoking when I wrote stuff... ::)

It still outputs the same thing, though. And the behaviour is still the same, no sound when main window is in focus, sound everywhere else. :-/

As for determining the driver the program is using, anyone know of an easy way to determine it?

Kitty Cat
Member #2,815
October 2002
avatar

digi_driver->name
digi_driver->desc
midi_driver->name
midi_driver->desc

EDIT: What if you put rest(0) in the while loop?

--
"Do not meddle in the affairs of cats, for they are subtle and will pee on your computer." -- Bruce Graham

Carrus85
Member #2,633
August 2002
avatar

Okay, the driver information the program reports is the following:

 digi_driver->name = Allegmix SoundMAX Digital Audio
 digi_driver->desc = Allegmix SoundMAX Digital Audio
 midi_driver->name = Microsoft MIDI Mapper
 midi_driver->desc = Microsoft MIDI Mapper

EDIT: Placing rest(0) in the while-loop causes the same results in the test program above; no sound while main window is in focus, sound everywhere else.

EDIT:

Test program now reads:

1// File: Test.c
2#include <allegro.h>
3 
4int main ( int argc, char **argv )
5{
6 int voices = 0;
7 allegro_init();
8 if ( set_gfx_mode ( GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0 ) < 0 )
9 {
10 printf ( "Graphics initialization failure, %s\n", allegro_error );
11 }
12 set_display_switch_mode ( SWITCH_BACKGROUND );
13 printf (" MIDI Testing Program\n" );
14 /* Test Variables */
15
16 install_keyboard ( );
17 MIDI *testMidi;
18
19
20
21 voices = detect_midi_driver ( MIDI_AUTODETECT );
22
23 if ( !voices )
24 {
25 printf ( " MIDI: No voices detected! Terminating! %s\n", allegro_error);
26 }
27 else if ( voices == 0xFFFF )
28 {
29 printf ( " MIDI: Driver Detected, but no way to determine voices\n" );
30 }
31 else if ( voices == -1 )
32 {
33 printf ( " MIDI: Driver Detected, voice stealing from DIGI Driver\n" );
34 }
35 else
36 {
37 printf ( " MIDI: Driver Detected! Voices = %d\n" , voices );
38 }
39
40 voices = 0;
41 voices = detect_digi_driver ( DIGI_AUTODETECT );
42
43 if ( !voices )
44 {
45 printf ( " DIGI: No Hardware Detected %s\n", allegro_error );
46 }
47 else
48 {
49 printf ( " DIGI: Digital Device Detected, Voices = %d\n", voices );
50 }
51
52 if ( install_sound (DIGI_AUTODETECT, MIDI_AUTODETECT, NULL) < 0 )
53 {
54 printf ( " Failure to initialize sound with MIDI. Error: %s\n", allegro_error );
55 return 0;
56 }
57 else
58 {
59 printf ( " Everything installed fine, I'm lost...\n");
60 }
61
62 testMidi = load_midi ( "Zelda2lc.mid" ); // got this midi file off of vgmusic.com
63 if ( play_midi ( testMidi, 0 ) != 0 )
64 {
65 printf ( " Failure to load midi file Zelda2lc.mid: %s\n", allegro_error );
66 if ( testMidi != NULL ) destroy_midi ( testMidi );
67 return 0;
68 }
69 else
70 printf ( " The Midi Loaded fine, do you hear anything? I'm guessing not\n" );
71
72 printf( " Driver information\n\n" );
73 printf( " digi_driver->name = %s\n", digi_driver->name );
74 printf( " digi_driver->desc = %s\n", digi_driver->desc );
75 printf( " midi_driver->name = %s\n", midi_driver->name );
76 printf( " midi_driver->desc = %s\n", midi_driver->desc );
77 while ( !key[KEY_ESC] )
78 rest( 0 );
79 destroy_midi ( testMidi );
80 return 0;
81} END_OF_MAIN()

A J
Member #3,025
December 2002
avatar

found a keyb scan code bug with the ALT key
http://www.allegro.cc/forums/view_thread.php?_id=484193

___________________________
The more you talk, the more AJ is right. - ML

Evert
Member #794
November 2000
avatar

Quote:

found a keyb scan code bug with the ALT key

I know. Mailing list only is fine for reporting bugs. ;)

A J
Member #3,025
December 2002
avatar

as discussed on #allegro, some folks dont think so ::)

___________________________
The more you talk, the more AJ is right. - ML

Elias
Member #358
May 2000

Who on #allegro? What did they tell you? Mailing list definitely is fine, unless you need some feedback to confirm it first by others (in which case, send first only here, then later to [AD] if no developer responds).

--
"Either help out or stop whining" - Evert

A J
Member #3,025
December 2002
avatar

there was a heated (+1.5 degrees) debate on #allegro about using mailing lists as the primary method for submitting patches/changes/bugs.

___________________________
The more you talk, the more AJ is right. - ML



Go to: