Develop and Download Open Source Software

Browse Subversion Repository

Contents of /trunk/Classes/QuantizePanelController.m

Parent Directory Parent Directory | Revision Log Revision Log


Revision 146 - (show annotations) (download)
Sun Dec 17 04:05:28 2017 UTC (6 years, 5 months ago) by toshinagata1964
File size: 3452 byte(s)
Xcode project is updated so that ppc/i386 universal binary can be built (as before)
1 //
2 // QuantizePanelController.m
3 // Alchemusica
4 //
5 // Created by Toshi Nagata on 12/01/14.
6 // Copyright 2012 __MyCompanyName__. All rights reserved.
7 //
8
9 #import "QuantizePanelController.h"
10 #import "MyAppController.h"
11
12 NSString
13 *QuantizeNoteKey = @"quantize.note", /* Expressed internally as timebase = 480 */
14 *QuantizeStrengthKey = @"quantize.strength",
15 *QuantizeSwingKey = @"quantize.swing";
16
17 @implementation QuantizePanelController
18
19 - (id)init
20 {
21 self = [super initWithWindowNibName:@"QuantizePanel"];
22 if (self) {
23 timebase = 480.0f;
24 }
25 return self;
26 }
27
28 - (void)updateDisplay
29 {
30 id obj;
31 int ival;
32 float fval;
33 obj = MyAppCallback_getObjectGlobalSettings(QuantizeNoteKey);
34 if (obj == nil) {
35 obj = [NSNumber numberWithFloat:480.0f];
36 MyAppCallback_setObjectGlobalSettings(QuantizeNoteKey, obj);
37 }
38 fval = [obj floatValue];
39 for (ival = 0; ival < 18; ival++) {
40 if ([[unitNotePopUp itemAtIndex:ival] tag] == fval) {
41 [unitNotePopUp selectItemAtIndex:ival];
42 break;
43 }
44 }
45 if (ival == 18)
46 [unitNotePopUp selectItemAtIndex:-1];
47 ival = (int)floor(fval * timebase / 480.0f + 0.5f);
48 [unitText setIntValue:ival];
49
50 obj = MyAppCallback_getObjectGlobalSettings(QuantizeStrengthKey);
51 if (obj == nil) {
52 obj = [NSNumber numberWithFloat:0.5f];
53 MyAppCallback_setObjectGlobalSettings(QuantizeStrengthKey, obj);
54 }
55 fval = [obj floatValue];
56 [strengthSlider setFloatValue:fval];
57 [strengthText setFloatValue:fval];
58
59 obj = MyAppCallback_getObjectGlobalSettings(QuantizeSwingKey);
60 if (obj == nil) {
61 obj = [NSNumber numberWithFloat:0.0f];
62 MyAppCallback_setObjectGlobalSettings(QuantizeSwingKey, obj);
63 }
64 fval = [obj floatValue];
65 [swingSlider setFloatValue:fval];
66 [swingText setFloatValue:fval];
67 }
68
69 - (void)windowDidLoad
70 {
71 NSMenu *menu;
72 NSMenuItem *menuItem;
73 int i, j;
74 [super windowDidLoad];
75 menu = [unitNotePopUp menu];
76 for (i = 0; i < 3; i++) {
77 static NSString *fmt[] = {@"note%d.png", @"note%dd.png", @"note%d_3.png"};
78 static int notelen[] = {1920, 2880, 1280};
79 for (j = 1; j <= 32; j *= 2) {
80 menuItem = [[[NSMenuItem allocWithZone: [self zone]] initWithTitle: @"" action: nil keyEquivalent: @""] autorelease];
81 [menuItem setImage: [NSImage imageNamed: [NSString stringWithFormat: fmt[i], j]]];
82 [menuItem setTag:notelen[i] / j]; /* Note length for timebase = 480 */
83 [menu addItem: menuItem];
84 }
85 }
86 [self updateDisplay];
87 }
88
89 - (void)setTimebase:(float)newTimebase
90 {
91 timebase = newTimebase;
92 [self updateDisplay];
93 }
94
95 - (IBAction)unitChanged:(id)sender
96 {
97 float fval;
98 if (sender == unitNotePopUp)
99 fval = [[sender selectedItem] tag];
100 else if (sender == unitText)
101 fval = [sender floatValue] * 480.0f / timebase;
102 else return;
103 MyAppCallback_setObjectGlobalSettings(QuantizeNoteKey, [NSNumber numberWithFloat:fval]);
104 [self updateDisplay];
105 }
106
107 - (IBAction)strengthChanged:(id)sender
108 {
109 float fval;
110 fval = [sender floatValue];
111 if (fval < 0.0f)
112 fval = 0.0f;
113 if (fval > 1.0f)
114 fval = 1.0f;
115 MyAppCallback_setObjectGlobalSettings(QuantizeStrengthKey, [NSNumber numberWithFloat:fval]);
116 [self updateDisplay];
117 }
118
119 - (IBAction)swingChanged:(id)sender
120 {
121 float fval;
122 fval = [sender floatValue];
123 if (fval < 0.0f)
124 fval = 0.0f;
125 if (fval > 1.0f)
126 fval = 1.0f;
127 MyAppCallback_setObjectGlobalSettings(QuantizeSwingKey, [NSNumber numberWithFloat:fval]);
128 [self updateDisplay];
129 }
130
131 - (IBAction)okPressed:(id)sender
132 {
133 [NSApp stopModal];
134 }
135
136 - (IBAction)cancelPressed:(id)sender
137 {
138 [NSApp abortModal];
139 }
140
141 @end

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