Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/Classes/EventFilterPanelController.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 117 - (show annotations) (download)
Sun Oct 1 03:33:45 2017 UTC (6 years, 6 months ago) by toshinagata1964
File size: 5072 byte(s)
Sizes of the integer types are reconsidered.
1 //
2 // EventFilterPanelController.m
3 // Alchemusica
4 //
5 /*
6 Copyright (c) 2008-2011 Toshi Nagata. All rights reserved.
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation version 2 of the License.
11
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16 */
17
18 #import "EventFilterPanelController.h"
19 #import "MDObjects.h"
20
21 NSString *gModeKey = @"mode",
22 *gChannelPressureKey = @"channelPressure",
23 *gNoteKey = @"note",
24 *gPitchBendKey = @"pitchBend",
25 *gPolyPressureKey = @"polyPressure",
26 *gProgramKey = @"program",
27 *gSysexKey = @"sysex",
28 *gCCMetaKey = @"ccMeta";
29
30 NSString *gCCMetaNameKey = @"name",
31 *gCCMetaSelectedKey = @"selected",
32 *gCCMetaNumberKey = @"number";
33
34 static short *sCCMetaToObjectIndex;
35 static short *sObjectIndexToCCMeta;
36
37 @implementation EventFilterPanelController
38
39 + (id)nameForCCMetaNumber: (int)number
40 {
41 MDEvent event;
42 int kind, code;
43 char buf[64];
44 MDEventInit(&event);
45 if (number >= 128) {
46 code = number - 128;
47 kind = MDEventSMFMetaNumberToEventKind(code);
48 MDSetKind(&event, kind);
49 MDSetCode(&event, code);
50 } else {
51 MDSetKind(&event, kMDEventControl);
52 MDSetCode(&event, number);
53 }
54 MDEventToKindString(&event, buf, sizeof buf);
55 return [NSString stringWithUTF8String: buf + 1];
56 }
57
58 - (id)init
59 {
60 self = [super initWithWindowNibName: @"EventFilterPanel"];
61 if (self == nil)
62 return nil;
63 if (sCCMetaToObjectIndex == NULL) {
64 // cc/meta number <-> object index conversion table
65 int i, j;
66 static const short wellKnowns[] = {
67 0, /* Bank select MSB */
68 1, /* Modulation */
69 5, /* Portamento time */
70 6, /* Data entry MSB */
71 7, /* Volume */
72 10, /* Pan */
73 11, /* Expression */
74 32, /* Bank select LSB */
75 64, /* Hold */
76 98, /* NRPN LSB */
77 99, /* NRPN MSB */
78 100, /* RPN LSB */
79 101, /* RPN MSB */
80 kMDMetaText + 128,
81 kMDMetaMarker + 128,
82 kMDMetaTempo + 128,
83 kMDMetaTimeSignature + 128,
84 kMDMetaKey + 128,
85 -1 };
86 sCCMetaToObjectIndex = (short *)malloc(sizeof(short) * 256);
87 sObjectIndexToCCMeta = (short *)malloc(sizeof(short) * 256);
88 for (i = 0; i < 256; i++)
89 sObjectIndexToCCMeta[i] = sCCMetaToObjectIndex[i] = -1;
90 for (i = 0; wellKnowns[i] >= 0; i++) {
91 sObjectIndexToCCMeta[i] = wellKnowns[i];
92 sCCMetaToObjectIndex[wellKnowns[i]] = i;
93 }
94 for (j = 0; j < 256; j++) {
95 if (sCCMetaToObjectIndex[j] >= 0)
96 continue;
97 sObjectIndexToCCMeta[i] = j;
98 sCCMetaToObjectIndex[j] = i;
99 i++;
100 }
101 }
102
103 return self;
104 }
105
106 - (void)ccMetaPopUpMenuSelected: (id)sender
107 {
108 // Set the text and cc/meta number for the selected row
109 int idx = (int)[ccMetaTableView selectedRow];
110 int tag = (int)[sender tag];
111 id obj;
112 if (idx < 0)
113 return;
114 obj = [[ccMetaFilters arrangedObjects] objectAtIndex: idx];
115 [obj setValue: [NSNumber numberWithInt: tag] forKey: gCCMetaNumberKey];
116 [obj setValue: [sender title] forKey: gCCMetaNameKey];
117 }
118
119 - (void)windowDidLoad
120 {
121 NSMutableDictionary *dict;
122
123 [super windowDidLoad];
124
125 {
126 // Set up the popup menu
127 NSMenu *menu, *submenu;
128 menu = [[[NSMenu alloc] initWithTitle: @"Meta and CC"] autorelease];
129 [menu addItemWithTitle: @"Control" action: nil keyEquivalent: @""];
130 submenu = MDMenuWithControlNames(self, @selector(ccMetaPopUpMenuSelected:), 0);
131 [[menu itemAtIndex: 0] setSubmenu: submenu];
132 [menu addItemWithTitle: @"Meta" action: nil keyEquivalent: @""];
133 submenu = MDMenuWithMetaNames(self, @selector(ccMetaPopUpMenuSelected:), 128);
134 [[menu itemAtIndex: 1] setSubmenu: submenu];
135 [ccMetaPopUp setMenu: menu];
136 }
137
138 dict = [NSMutableDictionary dictionary];
139 [filters setContent: dict];
140 [[filters content] setValue: [NSNumber numberWithInt: 0] forKey: gModeKey];
141 }
142
143 - (void)setMode: (int)mode
144 {
145 [[filters content] setValue: [NSNumber numberWithInt: mode] forKey: gModeKey];
146 }
147
148 - (int)mode
149 {
150 return [[[filters content] valueForKey: gModeKey] intValue];
151 }
152
153 - (void)select: (BOOL)flag forKey: (id)key
154 {
155 [[filters content] setValue: [NSNumber numberWithBool: flag] forKey: key];
156 }
157
158 - (BOOL)isSelectedForKey: (id)key
159 {
160 return [[[filters content] valueForKey: key] boolValue];
161 }
162
163 - (IBAction)okPressed:(id)sender
164 {
165 [[NSApplication sharedApplication] endSheet: [self window] returnCode: 1];
166 }
167
168 - (id)ccMetaFilters
169 {
170 return [ccMetaFilters arrangedObjects];
171 }
172
173 - (void)addNewCCMetaFilter: (int)number selected: (BOOL)selected
174 {
175 [ccMetaFilters addObject:
176 [NSMutableDictionary dictionaryWithObjectsAndKeys:
177 [NSNumber numberWithInt: number], gCCMetaNumberKey,
178 [NSNumber numberWithBool: selected], gCCMetaSelectedKey,
179 [[self class] nameForCCMetaNumber: number], gCCMetaNameKey,
180 nil]];
181 }
182
183 - (IBAction)cancelPressed:(id)sender
184 {
185 [[NSApplication sharedApplication] endSheet: [self window] returnCode: 0];
186 }
187
188 - (IBAction)addNewCCMetaEntry: (id)sender
189 {
190 [self addNewCCMetaFilter: 0 selected: YES];
191 }
192
193 @end

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26