Skip to content

Commit 3c5eae7

Browse files
committed
pass through keydown/keyup events (not quite working)
1 parent 59c2cdf commit 3c5eae7

File tree

6 files changed

+205
-39
lines changed

6 files changed

+205
-39
lines changed

src/libprojectM/carbontoprojectM.h

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,11 @@ r/**
2929
#ifndef _CARBONTOPROJECTM_H
3030
#define _CARBONTOPROJECTM_H
3131

32-
#include "event.h"
33-
3432
#ifdef WIN32
3533
#else
3634
#endif
3735

38-
projectMEvent carbon2pmEvent( EventRecord *event ) {
39-
40-
switch ( event->what ) {
41-
case updateEvt:
42-
return PROJECTM_VIDEORESIZE;
43-
case keyUp:
44-
return PROJECTM_KEYUP;
45-
case keyDown:
46-
return PROJECTM_KEYDOWN;
47-
default:
48-
return PROJECTM_KEYUP;
49-
}
50-
}
51-
52-
projectMKeycode carbon2pmKeycode( EventRecord *event ) {
36+
projectMKeycode carbon2pmKeycode( NSEvent *event ) {
5337
projectMKeycode char_code = (projectMKeycode)(event->message & charCodeMask);
5438
switch ( char_code ) {
5539
case kFunctionKeyCharCode: {
@@ -98,7 +82,7 @@ projectMKeycode carbon2pmKeycode( EventRecord *event ) {
9882
}
9983
}
10084

101-
projectMModifier carbon2pmModifier( EventRecord *event ) {
85+
projectMModifier carbon2pmModifier( NSEvent *event ) {
10286
return (projectMModifier)PROJECTM_K_LSHIFT;
10387
}
10488

src/libprojectM/cocoatoprojectM.h

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/**
2+
* projectM -- Milkdrop-esque visualisation SDK
3+
* Copyright (C)2003-2007 projectM Team
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation; either
8+
* version 2.1 of the License, or (at your option) any later version.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18+
* See 'LICENSE.txt' included within this release
19+
*
20+
*/
21+
/**
22+
*
23+
* Translates cocoa -> projectM variables
24+
*
25+
* $Log$
26+
*/
27+
28+
#ifndef _CARBONTOPROJECTM_H
29+
#define _CARBONTOPROJECTM_H
30+
31+
#ifdef WIN32
32+
#else
33+
#endif
34+
35+
projectMKeycode cocoa2pmKeycode( NSEvent *event ) {
36+
projectMKeycode char_code = (projectMKeycode)[event keyCode];
37+
switch ( char_code ) {
38+
case kFunctionKeyCharCode: {
39+
switch ( ( char_code << 16 ) >> 24 ) {
40+
case 111: {
41+
return PROJECTM_K_F12;
42+
}
43+
case 103: {
44+
return PROJECTM_K_F11;
45+
}
46+
case 109: {
47+
return PROJECTM_K_F10;
48+
}
49+
case 101: {
50+
return PROJECTM_K_F9;
51+
}
52+
case 100: {
53+
return PROJECTM_K_F8;
54+
}
55+
case 98: {
56+
return PROJECTM_K_F7;
57+
}
58+
case 97: {
59+
return PROJECTM_K_F6;
60+
}
61+
case 96: {
62+
return PROJECTM_K_F5;
63+
}
64+
case 118: {
65+
return PROJECTM_K_F4;
66+
}
67+
case 99: {
68+
return PROJECTM_K_F3;
69+
}
70+
case 120: {
71+
return PROJECTM_K_F2;
72+
}
73+
case 122: {
74+
return PROJECTM_K_F1;
75+
}
76+
}
77+
}
78+
default: {
79+
return char_code;
80+
}
81+
}
82+
}
83+
84+
projectMModifier cocoa2pmModifier( NSEvent *event ) {
85+
NSUInteger mod = [event modifierFlags];
86+
if (mod & NSShiftKeyMask)
87+
return (projectMModifier)PROJECTM_K_LSHIFT;
88+
if (mod & NSControlKeyMask)
89+
return (projectMModifier)PROJECTM_K_LCTRL;
90+
91+
return (projectMModifier)0;
92+
}
93+
94+
#endif /** _CARBONTOPROJECTM_H */

src/projectM-iTunes/iProjectM.xcodeproj/project.pbxproj

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,27 @@
2222
C3FAF97717B89F7400F4B110 /* shaders in CopyFiles */ = {isa = PBXBuildFile; fileRef = C3FAF97617B89F7200F4B110 /* shaders */; };
2323
C3FAF97817B89F7B00F4B110 /* config.inp in CopyFiles */ = {isa = PBXBuildFile; fileRef = C3FAF97517B89F7200F4B110 /* config.inp */; };
2424
C3FAF97B17B8A45200F4B110 /* fonts in CopyFiles */ = {isa = PBXBuildFile; fileRef = C3FAF97917B8A43B00F4B110 /* fonts */; };
25+
C3FAF98417B8C06900F4B110 /* GLEW.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C3FAF98317B8C05800F4B110 /* GLEW.framework */; };
26+
C3FAF98617B8C09D00F4B110 /* Cg.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = C3FAF98517B8C09D00F4B110 /* Cg.framework */; };
2527
/* End PBXBuildFile section */
2628

29+
/* Begin PBXContainerItemProxy section */
30+
C3FAF98217B8C05800F4B110 /* PBXContainerItemProxy */ = {
31+
isa = PBXContainerItemProxy;
32+
containerPortal = C3FAF97E17B8C05800F4B110 /* GLEW.xcodeproj */;
33+
proxyType = 2;
34+
remoteGlobalIDString = 8DC2EF5B0486A6940098B216;
35+
remoteInfo = GLEW;
36+
};
37+
C3FAF98717B8C10700F4B110 /* PBXContainerItemProxy */ = {
38+
isa = PBXContainerItemProxy;
39+
containerPortal = C3FAF97E17B8C05800F4B110 /* GLEW.xcodeproj */;
40+
proxyType = 1;
41+
remoteGlobalIDString = 8DC2EF4F0486A6940098B216;
42+
remoteInfo = GLEW;
43+
};
44+
/* End PBXContainerItemProxy section */
45+
2746
/* Begin PBXCopyFilesBuildPhase section */
2847
C3FAE5A917B898BB00F4B110 /* CopyFiles */ = {
2948
isa = PBXCopyFilesBuildPhase;
@@ -80,13 +99,17 @@
8099
C3FAF97517B89F7200F4B110 /* config.inp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = config.inp; sourceTree = "<group>"; };
81100
C3FAF97617B89F7200F4B110 /* shaders */ = {isa = PBXFileReference; lastKnownFileType = folder; path = shaders; sourceTree = "<group>"; };
82101
C3FAF97917B8A43B00F4B110 /* fonts */ = {isa = PBXFileReference; lastKnownFileType = folder; name = fonts; path = ../../fonts; sourceTree = "<group>"; };
102+
C3FAF97E17B8C05800F4B110 /* GLEW.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = GLEW.xcodeproj; path = "../../../../Downloads/projectM-complete-2.1.0-Source/src/macos/glew-1.4.0/Mac/GLEW.xcodeproj"; sourceTree = "<group>"; };
103+
C3FAF98517B8C09D00F4B110 /* Cg.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cg.framework; path = /Library/Frameworks/Cg.framework; sourceTree = "<absolute>"; };
83104
/* End PBXFileReference section */
84105

85106
/* Begin PBXFrameworksBuildPhase section */
86107
C3F9D7AC17B82CC3009E58CB /* Frameworks */ = {
87108
isa = PBXFrameworksBuildPhase;
88109
buildActionMask = 2147483647;
89110
files = (
111+
C3FAF98617B8C09D00F4B110 /* Cg.framework in Frameworks */,
112+
C3FAF98417B8C06900F4B110 /* GLEW.framework in Frameworks */,
90113
C3F9D7CF17B831F3009E58CB /* OpenGL.framework in Frameworks */,
91114
C3F9D7B317B82CC3009E58CB /* Cocoa.framework in Frameworks */,
92115
C3FAE59D17B88BF800F4B110 /* libprojectM.a in Frameworks */,
@@ -102,6 +125,7 @@
102125
C3F9D7A617B82CC3009E58CB = {
103126
isa = PBXGroup;
104127
children = (
128+
C3FAF97E17B8C05800F4B110 /* GLEW.xcodeproj */,
105129
C3FAF97A17B8A44100F4B110 /* share */,
106130
C3FAE5A417B88C5B00F4B110 /* libprojectM */,
107131
C3FAE59917B88B9000F4B110 /* iProjectM */,
@@ -127,6 +151,7 @@
127151
C3F9D7B117B82CC3009E58CB /* Frameworks */ = {
128152
isa = PBXGroup;
129153
children = (
154+
C3FAF98517B8C09D00F4B110 /* Cg.framework */,
130155
C3F9D7CE17B831F3009E58CB /* OpenGL.framework */,
131156
C3F9D7B217B82CC3009E58CB /* Cocoa.framework */,
132157
C3F9D7B417B82CC3009E58CB /* Other Frameworks */,
@@ -199,6 +224,14 @@
199224
name = share;
200225
sourceTree = "<group>";
201226
};
227+
C3FAF97F17B8C05800F4B110 /* Products */ = {
228+
isa = PBXGroup;
229+
children = (
230+
C3FAF98317B8C05800F4B110 /* GLEW.framework */,
231+
);
232+
name = Products;
233+
sourceTree = "<group>";
234+
};
202235
/* End PBXGroup section */
203236

204237
/* Begin PBXNativeTarget section */
@@ -215,6 +248,7 @@
215248
buildRules = (
216249
);
217250
dependencies = (
251+
C3FAF98817B8C10700F4B110 /* PBXTargetDependency */,
218252
);
219253
name = iProjectM;
220254
productName = iProjectM;
@@ -240,13 +274,29 @@
240274
mainGroup = C3F9D7A617B82CC3009E58CB;
241275
productRefGroup = C3F9D7B017B82CC3009E58CB /* Products */;
242276
projectDirPath = "";
277+
projectReferences = (
278+
{
279+
ProductGroup = C3FAF97F17B8C05800F4B110 /* Products */;
280+
ProjectRef = C3FAF97E17B8C05800F4B110 /* GLEW.xcodeproj */;
281+
},
282+
);
243283
projectRoot = "";
244284
targets = (
245285
C3F9D7AE17B82CC3009E58CB /* iProjectM */,
246286
);
247287
};
248288
/* End PBXProject section */
249289

290+
/* Begin PBXReferenceProxy section */
291+
C3FAF98317B8C05800F4B110 /* GLEW.framework */ = {
292+
isa = PBXReferenceProxy;
293+
fileType = wrapper.framework;
294+
path = GLEW.framework;
295+
remoteRef = C3FAF98217B8C05800F4B110 /* PBXContainerItemProxy */;
296+
sourceTree = BUILT_PRODUCTS_DIR;
297+
};
298+
/* End PBXReferenceProxy section */
299+
250300
/* Begin PBXShellScriptBuildPhase section */
251301
C3FAE5AB17B898F800F4B110 /* Generate Installer Package */ = {
252302
isa = PBXShellScriptBuildPhase;
@@ -278,6 +328,14 @@
278328
};
279329
/* End PBXSourcesBuildPhase section */
280330

331+
/* Begin PBXTargetDependency section */
332+
C3FAF98817B8C10700F4B110 /* PBXTargetDependency */ = {
333+
isa = PBXTargetDependency;
334+
name = GLEW;
335+
targetProxy = C3FAF98717B8C10700F4B110 /* PBXContainerItemProxy */;
336+
};
337+
/* End PBXTargetDependency section */
338+
281339
/* Begin XCBuildConfiguration section */
282340
C3F9D7BF17B82CC3009E58CB /* Debug */ = {
283341
isa = XCBuildConfiguration;
@@ -293,6 +351,7 @@
293351
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
294352
COPY_PHASE_STRIP = NO;
295353
DEPLOYMENT_LOCATION = YES;
354+
FRAMEWORK_SEARCH_PATHS = /Library/Frameworks;
296355
GCC_C_LANGUAGE_STANDARD = "compiler-default";
297356
GCC_DYNAMIC_NO_PIC = NO;
298357
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
@@ -328,6 +387,7 @@
328387
COPY_PHASE_STRIP = YES;
329388
DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym";
330389
DEPLOYMENT_LOCATION = YES;
390+
FRAMEWORK_SEARCH_PATHS = /Library/Frameworks;
331391
GCC_C_LANGUAGE_STANDARD = "compiler-default";
332392
GCC_ENABLE_OBJC_EXCEPTIONS = YES;
333393
GCC_WARN_64_TO_32_BIT_CONVERSION = YES;

src/projectM-iTunes/iprojectM.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,5 +162,6 @@ OSStatus ConfigureVisual( VisualPluginData * visualPluginData );
162162

163163
void initProjectM( VisualPluginData * visualPluginData );
164164
void renderProjectMTexture( VisualPluginData * visualPluginData );
165+
void keypressProjectM( VisualPluginData * visualPluginData, projectMEvent event, projectMKeycode keycode, projectMModifier mod );
165166

166167
#endif

src/projectM-iTunes/iprojectM.mm

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ void initProjectM( VisualPluginData * visualPluginData ) {
1515
pm->selectRandom(true);
1616
}
1717

18+
void keypressProjectM( VisualPluginData * visualPluginData, projectMEvent event, projectMKeycode keycode, projectMModifier mod ) {
19+
visualPluginData->pm->key_handler(event, keycode, mod);
20+
}
21+
1822
void renderProjectMTexture( VisualPluginData * visualPluginData ){
1923
static int textureHandle = visualPluginData->pm->initRenderToTexture();
2024

src/projectM-iTunes/iprojectM_mac.mm

Lines changed: 44 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,14 @@
99
#import <OpenGL/gl.h>
1010
#import <OpenGL/glu.h>
1111
#import <string.h>
12+
#include "libprojectM/cocoatoprojectM.h"
1213

13-
//-------------------------------------------------------------------------------------------------
14-
// constants, etc.
15-
//-------------------------------------------------------------------------------------------------
16-
17-
#define kTVisualPluginName CFSTR("projectM")
14+
#define kTVisualPluginName CFSTR("projectM")
1815

1916
extern "C" OSStatus iTunesPluginMainMachO( OSType inMessage, PluginMessageInfo *inMessageInfoPtr, void *refCon ) __attribute__((visibility("default")));
2017

18+
static bool _keypressProjectM( VisualPluginData * visualPluginData, projectMEvent eventType, NSEvent *event );
19+
2120
#if USE_SUBVIEW
2221
@interface VisualView : NSOpenGLView
2322
{
@@ -63,6 +62,10 @@ void DrawVisual( VisualPluginData * visualPluginData )
6362

6463
glFlush();
6564

65+
return;
66+
67+
// TODO: artwork overlay
68+
6669
// should we draw the info/artwork in the bottom-left corner?
6770
time_t theTime = time( NULL );
6871

@@ -95,6 +98,7 @@ void DrawVisual( VisualPluginData * visualPluginData )
9598
}
9699
}
97100

101+
98102
//-------------------------------------------------------------------------------------------------
99103
// UpdateArtwork
100104
//-------------------------------------------------------------------------------------------------
@@ -292,24 +296,43 @@ - (BOOL)resignFirstResponder
292296
return YES;
293297
}
294298

295-
//-------------------------------------------------------------------------------------------------
296-
// keyDown
297-
//-------------------------------------------------------------------------------------------------
298-
//
299-
-(void)keyDown:(NSEvent *)theEvent
300-
{
301-
// Handle key events here.
302-
// Do not eat the space bar, ESC key, TAB key, or the arrow keys: iTunes reserves those keys.
299+
- (void)keyDown:(NSEvent *)event {
300+
if ( _keypressProjectM( _visualPluginData, PROJECTM_KEYDOWN, event ) )
301+
return;
303302

304-
// if the 'i' key is pressed, reset the info timeout so that we draw it again
305-
if ( [[theEvent charactersIgnoringModifiers] isEqualTo:@"i"] )
306-
{
307-
UpdateInfoTimeOut( _visualPluginData );
308-
return;
309-
}
303+
[super keyDown:event];
304+
}
305+
306+
- (void)keyUp:(NSEvent *)event {
307+
if ( _keypressProjectM( _visualPluginData, PROJECTM_KEYUP, event ) )
308+
return;
309+
310+
[super keyUp:event];
311+
}
310312

311-
// Pass all unhandled events up to super so that iTunes can handle them.
312-
[super keyDown:theEvent];
313+
static bool _keypressProjectM( VisualPluginData * visualPluginData, projectMEvent eventType, NSEvent *eventRec ) {
314+
// Handle key events here.
315+
// Do not eat the space bar, ESC key, TAB key, or the arrow keys: iTunes reserves those keys.
316+
317+
projectMKeycode keycode = cocoa2pmKeycode(eventRec);
318+
projectMModifier mod = cocoa2pmModifier(eventRec);
319+
320+
switch ([eventRec keyCode]) {
321+
case kVK_Tab:
322+
case kVK_Space:
323+
case kVK_LeftArrow:
324+
case kVK_RightArrow:
325+
case kVK_UpArrow:
326+
case kVK_DownArrow:
327+
case kVK_Escape:
328+
break;
329+
330+
default:
331+
keypressProjectM( visualPluginData, eventType, keycode, mod );
332+
return true;
333+
}
334+
335+
return false;
313336
}
314337

315338
@end

0 commit comments

Comments
 (0)