• R/O
  • SSH
  • HTTPS

alchemusica: 提交


Commit MetaInfo

修订版201 (tree)
时间2022-04-14 23:18:07
作者toshinagata1964

Log Message

Value resolution in the strip chart can be selected from 0.25,0.5,1,2,4.

更改概述

差异

--- trunk/Classes/GraphicSplitterView.h (revision 200)
+++ trunk/Classes/GraphicSplitterView.h (revision 201)
@@ -22,7 +22,9 @@
2222 MyPopUpButton *kindPopup;
2323 MyPopUpButton *codePopup;
2424 MyPopUpButton *trackPopup;
25+ MyPopUpButton *resolutionPopup;
2526 NSTextField *trackLabelText;
27+ NSTextField *resolutionLabelText;
2628 NSMenu *controlSubmenu;
2729 }
2830
--- trunk/Classes/GraphicSplitterView.m (revision 200)
+++ trunk/Classes/GraphicSplitterView.m (revision 201)
@@ -41,6 +41,17 @@
4141 { kMDEventTempo, @"Tempo" }
4242 };
4343
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+
4455 /*static NSMenuItem *
4556 searchMenuItemWithTag(NSMenu *menu, int tag)
4657 {
@@ -84,11 +95,22 @@
8495 trackLabelText = [[[NSTextField allocWithZone:[self zone]] initWithFrame:rect] autorelease];
8596 rect.origin.y += 2;
8697 rect.origin.x += rect.size.width + 4.0f;
87- rect.size.width = 160.0f;
98+ rect.size.width = 120.0f;
8899 trackPopup = [[[MyPopUpButton allocWithZone:[self zone]] initWithFrame:rect] autorelease];
89100 [trackPopup setBezelStyle: NSShadowlessSquareBezelStyle];
90101 [trackPopup setBackgroundColor:[NSColor whiteColor]];
91102 [[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];
92114 font = [NSFont systemFontOfSize: [NSFont smallSystemFontSize]];
93115 [kindPopup setFont: font];
94116 [codePopup setFont: font];
@@ -96,10 +118,16 @@
96118 [trackLabelText setSelectable:NO];
97119 [trackLabelText setDrawsBackground:NO];
98120 [trackPopup setFont: font];
121+ [resolutionLabelText setBezeled:NO];
122+ [resolutionLabelText setSelectable:NO];
123+ [resolutionLabelText setDrawsBackground:NO];
124+ [resolutionPopup setFont: font];
99125 [self addSubview: kindPopup];
100126 [self addSubview: codePopup];
101127 [self addSubview: trackLabelText];
102128 [self addSubview: trackPopup];
129+ [self addSubview: resolutionLabelText];
130+ [self addSubview: resolutionPopup];
103131 for (i = 0; i < sizeof(sKindMenuItems) / sizeof(sKindMenuItems[0]); i++) {
104132 [kindPopup addItemWithTitle: sKindMenuItems[i].title];
105133 [[kindPopup itemAtIndex: i] setTag: sKindMenuItems[i].kind];
@@ -108,9 +136,16 @@
108136 [kindPopup setEnabled: YES];
109137 [codePopup setEnabled: NO];
110138 [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];
111144 font = [NSFont systemFontOfSize: [NSFont smallSystemFontSize] - 2];
112145 [trackLabelText setFont: font];
113146 [trackLabelText setStringValue:@"Track:"];
147+ [resolutionLabelText setFont: font];
148+ [resolutionLabelText setStringValue:@"Resolution:"];
114149 }
115150 return self;
116151 }
@@ -170,6 +205,8 @@
170205 [trackPopup setTarget:target];
171206 [trackPopup setAction:@selector(trackPopUpPressedInSplitterView:)];
172207 [trackPopup setMenu:[self makeTrackPopup]];
208+ [resolutionPopup setTarget: self];
209+ [resolutionPopup setAction: @selector(resolutionMenuItemSelected:)];
173210 }
174211
175212 - (void)drawRect:(NSRect)rect {
@@ -227,6 +264,15 @@
227264 [controller codeMenuItemSelected:(NSMenuItem *)sender inSplitterView:self];
228265 }
229266
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+
230276 - (void)setKindAndCode: (int32_t)kindAndCode
231277 {
232278 int kind, code;
--- trunk/Classes/GraphicWindowController.h (revision 200)
+++ trunk/Classes/GraphicWindowController.h (revision 201)
@@ -204,6 +204,7 @@
204204 - (void)setStripChartAtIndex: (int)index kind: (int)kind code: (int)code;
205205 - (IBAction)kindPopUpPressed: (id)sender;
206206 - (void)codeMenuItemSelected: (NSMenuItem *)item inSplitterView: (GraphicSplitterView *)view;
207+- (void)setResolution: (float)resolution inSplitterView: (GraphicSplitterView *)view;
207208 - (IBAction)trackPopUpPressedInSplitterView: (id)sender;
208209
209210 - (IBAction)expandHorizontally: (id)sender;
--- trunk/Classes/GraphicWindowController.m (revision 200)
+++ trunk/Classes/GraphicWindowController.m (revision 201)
@@ -1180,6 +1180,13 @@
11801180 [records[index].ruler setNeedsDisplay: YES];
11811181 }
11821182
1183+- (void)setStripChartAtIndex:(int)index resolution:(float)resolution
1184+{
1185+ if (![records[index].client isKindOfClass: [StripChartView class]])
1186+ return;
1187+ [(StripChartView *)records[index].client setResolution:resolution];
1188+}
1189+
11831190 - (void)setStripChartAtIndex:(int)index track:(int)track
11841191 {
11851192 int32_t kindAndCode, kind, code;
@@ -1221,6 +1228,17 @@
12211228 }
12221229 }
12231230
1231+- (void)setResolution: (float)resolution inSplitterView: (GraphicSplitterView *)view
1232+{
1233+ int i, code;
1234+ for (i = 1; i < myClientViewsCount; i++) {
1235+ if (records[i].splitter == view) {
1236+ [self setStripChartAtIndex: i resolution: resolution];
1237+ break;
1238+ }
1239+ }
1240+}
1241+
12241242 - (IBAction)trackPopUpPressedInSplitterView: (id)sender
12251243 {
12261244 int i, track;
--- trunk/Classes/StripChartView.h (revision 200)
+++ trunk/Classes/StripChartView.h (revision 201)
@@ -46,6 +46,9 @@
4646 int deltaDraggedValue;
4747 int32_t deltaDraggedTick;
4848
49+ // Resolution of the y value. Usually 1.0, but can be other values.
50+ float resolution;
51+
4952 // The center y coordinate when dragging is started; this is the baseline for add/sub or scale tool
5053 CGFloat centerY;
5154 }
@@ -52,6 +55,7 @@
5255
5356 - (void)setKindAndCode: (int32_t)kindAndCode;
5457 - (int32_t)kindAndCode;
58+- (void)setResolution: (float)resolution;
5559
5660 // Dragging support (accompanying PianoRollView)
5761 - (void)startExternalDraggingAtPoint:(NSPoint)aPoint mode:(int)aMode;
--- trunk/Classes/StripChartView.m (revision 200)
+++ trunk/Classes/StripChartView.m (revision 201)
@@ -60,6 +60,7 @@
6060 maxValue = 128.0f;
6161 calib = NULL;
6262 focusTrack = -1;
63+ resolution = 1.0;
6364 }
6465 return self;
6566 }
@@ -132,7 +133,7 @@
132133 - (float)convertToYValue:(CGFloat)y
133134 {
134135 NSRect bounds = [self bounds];
135- return (float)(floor((y - bounds.origin.y - sVerticalMargin) * (maxValue - minValue) / (bounds.size.height - sVerticalMargin * 2) + 0.5) + minValue);
136+ return (float)(floor(((y - bounds.origin.y - sVerticalMargin) * (maxValue - minValue) / (bounds.size.height - sVerticalMargin * 2)) / resolution + 0.5) * resolution + minValue);
136137 }
137138
138139 - (void)drawVelocityInRect: (NSRect)aRect
@@ -471,6 +472,12 @@
471472 [self updateCenterY];
472473 }
473474
475+- (void)setResolution: (float)resolution
476+{
477+ self->resolution = resolution;
478+}
479+
480+
474481 - (BOOL)isFocusTrack: (int)trackNum
475482 {
476483 if (focusTrack >= 0)
@@ -477,6 +484,7 @@
477484 return (trackNum == focusTrack);
478485 else return [super isFocusTrack:trackNum];
479486 }
487+
480488 - (int32_t)visibleTrackCount
481489 {
482490 if (focusTrack >= 0)
@@ -878,6 +886,7 @@
878886 MDPointer *mdptr;
879887 float fromValue, toValue;
880888 float pixelsPerTick, height;
889+ float valueResolution = resolution;
881890 const float *p;
882891 float v1, v2;
883892 int editingMode;
@@ -971,10 +980,13 @@
971980 v = v * (toValue - fromValue) + fromValue;
972981 // Generate an event
973982 MDSetTick(&event, tick);
974- if (eventKind == kMDEventTempo)
975- MDSetTempo(&event, (float)floor(v));
976- else
977- MDSetData1(&event, (int)floor(v));
983+ if (eventKind == kMDEventTempo) {
984+ v = floor(v / valueResolution) * valueResolution;
985+ MDSetTempo(&event, v);
986+ } else {
987+ v = floor(floor(v / valueResolution) * valueResolution);
988+ MDSetData1(&event, (int)(v));
989+ }
978990 if (v != v0 || tick >= toTick) {
979991 MDPointerInsertAnEvent(mdptr, &event);
980992 v0 = v;
@@ -990,7 +1002,7 @@
9901002 if (fabs(toValue - fromValue) < 1e-6)
9911003 tick3 = toTick;
9921004 else
993- tick3 = tick + (MDTickType)floor(fabs(sValueResolution / (toValue - fromValue) * (toTick - fromTick)));
1005+ tick3 = tick + (MDTickType)floor(fabs(valueResolution / (toValue - fromValue) * (toTick - fromTick)));
9941006 if (tick3 > tick2)
9951007 tick2 = tick3;
9961008 }
@@ -1016,10 +1028,13 @@
10161028 // Generate an event
10171029 MDSetTick(&event, (MDTickType)(x * (t2 - t1) + t1));
10181030 v = y * (v2 - v1) + v1;
1019- if (eventKind == kMDEventTempo)
1020- MDSetTempo(&event, (float)floor(v));
1021- else
1022- MDSetData1(&event, (int)floor(v));
1031+ if (eventKind == kMDEventTempo) {
1032+ v = floor(v / valueResolution) * valueResolution;
1033+ MDSetTempo(&event, v);
1034+ } else {
1035+ v = floor(floor(v / valueResolution) * valueResolution);
1036+ MDSetData1(&event, (int)v);
1037+ }
10231038 MDPointerInsertAnEvent(mdptr, &event);
10241039 // NSLog(@"t=%f tick=%ld value=%d", t, (MDTickType)(x * (t2 - t1) + t1), (int)floor(v));
10251040 }
@@ -1047,7 +1062,7 @@
10471062 if (v1 == v2 || p[1] == p[7]) {
10481063 tc = 1.0f;
10491064 } else {
1050- yc = (float)((double)sValueResolution / (v2 - v1));
1065+ yc = valueResolution / (v2 - v1);
10511066 if (p[1] < p[7]) {
10521067 yc = y + (float)fabs(yc);
10531068 if (yc < p[7])
@@ -1168,7 +1183,7 @@
11681183 if (editingMode == kGraphicAddMode) {
11691184 // The center line will be zero
11701185 float cy = [self convertToYValue:centerY];
1171- v = v0 + floor(v + 0.5 - cy);
1186+ v = v0 + v - cy;
11721187 } else if (editingMode == kGraphicScaleMode) {
11731188 // The visible vertical range is 0..200%
11741189 float visibleHeight = [[self superview] bounds].size.height;
@@ -1175,13 +1190,11 @@
11751190 float cy = [self convertToYValue:centerY];
11761191 float fully = [self convertToYValue:(centerY + visibleHeight * 0.5)];
11771192 if (fully > cy)
1178- v = floor(v0 * ((v - cy) / (fully - cy) + 1.0) + 0.5);
1193+ v = v0 * ((v - cy) / (fully - cy) + 1.0);
11791194 } else if (editingMode == kGraphicLimitMaxMode) {
1180- v = floor(v + 0.5);
11811195 if (v0 < v)
11821196 v = v0;
11831197 } else if (editingMode == kGraphicLimitMinMode) {
1184- v = floor(v + 0.5);
11851198 if (v0 > v)
11861199 v = v0;
11871200 }
@@ -1189,6 +1202,9 @@
11891202 v = minValue;
11901203 else if (v > maxValue)
11911204 v = maxValue;
1205+ v = floor(v / valueResolution) * valueResolution;
1206+ if (eventKind != kMDEventTempo)
1207+ v = floor(v);
11921208 fp[j] = v;
11931209 }
11941210 MDPointerRelease(mdptr);
Show on old repository browser