Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/Classes/GraphicSplitterView.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 201 - (show annotations) (download)
Thu Apr 14 14:18:07 2022 UTC (2 years, 1 month ago) by toshinagata1964
File size: 10887 byte(s)
Value resolution in the strip chart can be selected from 0.25,0.5,1,2,4.
1 //
2 // GraphicSplitterView.m
3 // Created by Toshi Nagata on Sun Feb 09 2003.
4 //
5 /*
6 Copyright (c) 2003-2016 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 "GraphicSplitterView.h"
19 #import "GraphicWindowController.h"
20 #import "MyDocument.h"
21 #import "MyMIDISequence.h"
22 #import "NSCursorAdditions.h"
23 #import "NSMenuAdditions.h"
24 #import "MDObjects.h"
25
26 @implementation GraphicSplitterView
27
28 // static NSMenu *sControlSubmenu;
29 // static NSMenu *sKeyPresSubmenu;
30
31 static struct sKindMenuItems {
32 int kind;
33 NSString *title;
34 } sKindMenuItems[] = {
35 { kMDEventNote, @"Note Velocity" },
36 { kMDEventInternalNoteOff, @"Release Velocity" },
37 { kMDEventControl, @"Control" },
38 { kMDEventPitchBend, @"Pitch Bend" },
39 { kMDEventChanPres, @"Channel Pressure" },
40 { kMDEventKeyPres, @"Key Pressure" },
41 { kMDEventTempo, @"Tempo" }
42 };
43
44 static struct sResolutionMenuItems {
45 float resolution;
46 NSString *title;
47 } sResolutionMenuItems[] = {
48 { 4.0f, @"4" },
49 { 2.0f, @"2" },
50 { 1.0f, @"1" },
51 { 0.5f, @"0.5" },
52 { 0.25f, @"0.25" }
53 };
54
55 /*static NSMenuItem *
56 searchMenuItemWithTag(NSMenu *menu, int tag)
57 {
58 int i;
59 NSMenuItem *item;
60 for (i = (int)[menu numberOfItems] - 1; i >= 0; i--) {
61 item = (NSMenuItem *)[menu itemAtIndex: i];
62 if ([item tag] == tag)
63 return item;
64 if ([item hasSubmenu]) {
65 item = searchMenuItemWithTag([item submenu], tag);
66 if (item != nil)
67 return item;
68 }
69 }
70 return nil;
71 }*/
72
73 - (id)initWithFrame:(NSRect)frame {
74 int i;
75 NSFont *font;
76 self = [super initWithFrame: frame];
77 if (self && frame.size.height >= 10.0) {
78 NSRect rect = [self bounds];
79 rect.origin.y++;
80 rect.size.height--;
81 rect.origin.x = 16.0f;
82 rect.size.width = 100.0f;
83 kindPopup = [[[MyPopUpButton allocWithZone: [self zone]] initWithFrame: rect] autorelease];
84 [kindPopup setBezelStyle: NSShadowlessSquareBezelStyle];
85 [kindPopup setBackgroundColor:[NSColor whiteColor]];
86 [[kindPopup cell] setControlSize:NSMiniControlSize];
87 rect.origin.x += rect.size.width + 16.0f;
88 codePopup = [[[MyPopUpButton allocWithZone: [self zone]] initWithFrame: rect] autorelease];
89 [codePopup setBezelStyle: NSShadowlessSquareBezelStyle];
90 [codePopup setBackgroundColor:[NSColor whiteColor]];
91 [[codePopup cell] setControlSize:NSMiniControlSize];
92 rect.origin.x += rect.size.width + 16.0f;
93 rect.size.width = 40.0f;
94 rect.origin.y -= 2;
95 trackLabelText = [[[NSTextField allocWithZone:[self zone]] initWithFrame:rect] autorelease];
96 rect.origin.y += 2;
97 rect.origin.x += rect.size.width + 4.0f;
98 rect.size.width = 120.0f;
99 trackPopup = [[[MyPopUpButton allocWithZone:[self zone]] initWithFrame:rect] autorelease];
100 [trackPopup setBezelStyle: NSShadowlessSquareBezelStyle];
101 [trackPopup setBackgroundColor:[NSColor whiteColor]];
102 [[trackPopup cell] setControlSize:NSMiniControlSize];
103 rect.origin.x += rect.size.width + 16.0f;
104 rect.size.width = 80.0f;
105 rect.origin.y -= 2;
106 resolutionLabelText = [[[NSTextField allocWithZone:[self zone]] initWithFrame:rect] autorelease];
107 rect.origin.y += 2;
108 rect.origin.x += rect.size.width + 4.0f;
109 rect.size.width = 40.0f;
110 resolutionPopup = [[[MyPopUpButton allocWithZone:[self zone]] initWithFrame:rect] autorelease];
111 [resolutionPopup setBezelStyle: NSShadowlessSquareBezelStyle];
112 [resolutionPopup setBackgroundColor:[NSColor whiteColor]];
113 [[resolutionPopup cell] setControlSize:NSMiniControlSize];
114 font = [NSFont systemFontOfSize: [NSFont smallSystemFontSize]];
115 [kindPopup setFont: font];
116 [codePopup setFont: font];
117 [trackLabelText setBezeled:NO];
118 [trackLabelText setSelectable:NO];
119 [trackLabelText setDrawsBackground:NO];
120 [trackPopup setFont: font];
121 [resolutionLabelText setBezeled:NO];
122 [resolutionLabelText setSelectable:NO];
123 [resolutionLabelText setDrawsBackground:NO];
124 [resolutionPopup setFont: font];
125 [self addSubview: kindPopup];
126 [self addSubview: codePopup];
127 [self addSubview: trackLabelText];
128 [self addSubview: trackPopup];
129 [self addSubview: resolutionLabelText];
130 [self addSubview: resolutionPopup];
131 for (i = 0; i < sizeof(sKindMenuItems) / sizeof(sKindMenuItems[0]); i++) {
132 [kindPopup addItemWithTitle: sKindMenuItems[i].title];
133 [[kindPopup itemAtIndex: i] setTag: sKindMenuItems[i].kind];
134 }
135 [kindPopup selectItemAtIndex: [kindPopup indexOfItemWithTag: kMDEventNote]];
136 [kindPopup setEnabled: YES];
137 [codePopup setEnabled: NO];
138 [trackPopup setEnabled: YES];
139 for (i = 0; i < sizeof(sResolutionMenuItems) / sizeof(sResolutionMenuItems[0]); i++) {
140 [resolutionPopup addItemWithTitle: sResolutionMenuItems[i].title];
141 }
142 [resolutionPopup selectItemAtIndex:2];
143 [resolutionPopup setEnabled: YES];
144 font = [NSFont systemFontOfSize: [NSFont smallSystemFontSize] - 2];
145 [trackLabelText setFont: font];
146 [trackLabelText setStringValue:@"Track:"];
147 [resolutionLabelText setFont: font];
148 [resolutionLabelText setStringValue:@"Resolution:"];
149 }
150 return self;
151 }
152
153 - (void)dealloc
154 {
155 if (controlSubmenu != nil)
156 [controlSubmenu release];
157 [super dealloc];
158 }
159
160 - (NSMenu *)makeTrackPopup
161 {
162 NSMenu *menu;
163 int i, count;
164 id target, doc;
165 MyMIDISequence *seq = nil;
166 target = [trackPopup target];
167 if (target != nil) {
168 doc = [target document];
169 if (doc != nil && [doc isKindOfClass:[MyDocument class]]) {
170 seq = [(MyDocument *)doc myMIDISequence];
171 }
172 }
173 if (seq != nil)
174 count = [seq trackCount];
175 else count = 0;
176 menu = [[[NSMenu alloc] initWithTitle: @"tracks"] autorelease];
177 for (i = 0; i <= count; i++) {
178 NSString *s;
179 if (i == 0)
180 s = @"(As Piano Roll)";
181 else {
182 NSString *name = [seq trackName:i - 1];
183 if (i == 1) {
184 s = [NSString stringWithFormat:@"C: %@", name];
185 } else {
186 s = [NSString stringWithFormat:@"%d: %@", i - 1, name];
187 }
188 }
189 [menu addItemWithTitle:s action:nil keyEquivalent:@""];
190 }
191 return menu;
192 }
193
194 // Initialize target-action relationship
195 - (void)viewDidMoveToSuperview
196 {
197 id target = [[[self superview] window] windowController];
198 [kindPopup setTarget: target];
199 [kindPopup setAction: @selector(kindPopUpPressed:)];
200 if (controlSubmenu == nil) {
201 controlSubmenu = [MDMenuWithControlNames(self, @selector(codeMenuItemSelected:), 0) retain];
202 }
203 [codePopup setTarget: target];
204 [codePopup setAction: @selector(codeMenuItemSelected:)];
205 [trackPopup setTarget:target];
206 [trackPopup setAction:@selector(trackPopUpPressedInSplitterView:)];
207 [trackPopup setMenu:[self makeTrackPopup]];
208 [resolutionPopup setTarget: self];
209 [resolutionPopup setAction: @selector(resolutionMenuItemSelected:)];
210 }
211
212 - (void)drawRect:(NSRect)rect {
213 NSRect bounds = [self bounds];
214 NSPoint pt1, pt2;
215 NSDrawWindowBackground(bounds);
216 [[NSColor lightGrayColor] set];
217 pt1.x = bounds.origin.x;
218 pt2.x = bounds.origin.x + bounds.size.width;
219 pt1.y = pt2.y = bounds.origin.y + 0.5f;
220 [NSBezierPath strokeLineFromPoint: pt1 toPoint: pt2];
221 pt1.y = pt2.y = bounds.origin.y + bounds.size.height - 0.5f;
222 [NSBezierPath strokeLineFromPoint: pt1 toPoint: pt2];
223 }
224
225 - (void)mouseDown: (NSEvent *)theEvent
226 {
227 NSPoint mousePt, startPt, origin;
228 NSEventType type;
229 GraphicWindowController *controller = (GraphicWindowController *)[[self window] windowController];
230 GraphicBackgroundView *container = [controller enclosingContainerForClientView:self];
231 startPt = [theEvent locationInWindow];
232 if (container != nil)
233 origin = [container frame].origin;
234 else origin = [self frame].origin;
235 [controller splitterViewStartedDragging:self];
236 do {
237 theEvent = [[self window] nextEventMatchingMask: NSLeftMouseUpMask | NSLeftMouseDraggedMask];
238 mousePt = [theEvent locationInWindow];
239 type = [theEvent type];
240 if (type != NSLeftMouseUp && type != NSLeftMouseDragged)
241 continue;
242 [controller splitterView: self isDraggedTo: origin.y + (mousePt.y - startPt.y) confirm: (type == NSLeftMouseUp)];
243 } while (type == NSLeftMouseDragged);
244 }
245
246 - (void)doMouseMoved:(NSEvent *)theEvent
247 {
248 NSPoint pt = [self convertPoint:[theEvent locationInWindow] fromView:nil];
249 if ((NSPointInRect(pt, [kindPopup frame]) && [kindPopup isEnabled])
250 || (NSPointInRect(pt, [trackPopup frame]) && [trackPopup isEnabled])
251 || (NSPointInRect(pt, [codePopup frame]) && [codePopup isEnabled]))
252 [[NSCursor arrowCursor] set];
253 else
254 [[NSCursor verticalMoveCursor] set];
255 }
256
257 - (void)createSubmenus
258 {
259 }
260
261 - (IBAction)codeMenuItemSelected:(id)sender
262 {
263 GraphicWindowController *controller = (GraphicWindowController *)[[self window] windowController];
264 [controller codeMenuItemSelected:(NSMenuItem *)sender inSplitterView:self];
265 }
266
267 - (IBAction)resolutionMenuItemSelected:(id)sender
268 {
269 int i;
270 GraphicWindowController *controller = (GraphicWindowController *)[[self window] windowController];
271 i = (int)[resolutionPopup indexOfSelectedItem];
272 if (i >= 0 && i < sizeof(sResolutionMenuItems) / sizeof(sResolutionMenuItems[0]))
273 [controller setResolution:sResolutionMenuItems[i].resolution inSplitterView:self];
274 }
275
276 - (void)setKindAndCode: (int32_t)kindAndCode
277 {
278 int kind, code;
279 NSMenuItem *item;
280 code = (kindAndCode & 65535);
281 kind = ((kindAndCode >> 16) & 65535);
282 if (kind != 65535) {
283 item = [[kindPopup menu] searchMenuItemWithTag:kind];
284 if (item != nil) {
285 [kindPopup selectItem: item];
286 if (kind == kMDEventControl) {
287 [codePopup setMenu: controlSubmenu];
288 [codePopup setEnabled: YES];
289 } else {
290 [codePopup setMenu: [[[NSMenu allocWithZone: [self zone]] initWithTitle: @""] autorelease]];
291 [codePopup setEnabled: NO];
292 }
293 }
294 }
295 if (code != 65535) {
296 item = [[codePopup menu] searchMenuItemWithTag:code];
297 if (item != nil) {
298 [codePopup selectItem: item];
299 }
300 }
301 }
302
303 - (void)setTrack:(int)track
304 {
305 [trackPopup selectItemAtIndex:track + 1];
306 }
307
308 - (void)rebuildTrackPopup
309 {
310 int n = (int)[trackPopup indexOfSelectedItem];
311 NSMenu *menu = [self makeTrackPopup];
312 [trackPopup setMenu:menu];
313 if (n >= 0 && n < [menu numberOfItems]) {
314 [trackPopup selectItemAtIndex:n];
315 }
316 }
317
318 @end

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