mirror of
https://github.com/microtherion/VocalEasel.git
synced 2024-12-22 11:14:00 +00:00
Handle lilypond path
This commit is contained in:
parent
32ef9e2386
commit
90f7099af9
3
English.lproj/MainMenu.nib/classes.nib
generated
3
English.lproj/MainMenu.nib/classes.nib
generated
|
@ -2,9 +2,10 @@
|
||||||
IBClasses = (
|
IBClasses = (
|
||||||
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
|
{CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; },
|
||||||
{
|
{
|
||||||
ACTIONS = {playNewPitch = id; };
|
ACTIONS = {playNewPitch = id; selectLilypondPath = id; };
|
||||||
CLASS = VLAppController;
|
CLASS = VLAppController;
|
||||||
LANGUAGE = ObjC;
|
LANGUAGE = ObjC;
|
||||||
|
OUTLETS = {lilypondPath = id; };
|
||||||
SUPERCLASS = NSObject;
|
SUPERCLASS = NSObject;
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
2
English.lproj/MainMenu.nib/info.nib
generated
2
English.lproj/MainMenu.nib/info.nib
generated
|
@ -13,8 +13,8 @@
|
||||||
<string>452.0</string>
|
<string>452.0</string>
|
||||||
<key>IBOpenObjects</key>
|
<key>IBOpenObjects</key>
|
||||||
<array>
|
<array>
|
||||||
<integer>217</integer>
|
|
||||||
<integer>29</integer>
|
<integer>29</integer>
|
||||||
|
<integer>217</integer>
|
||||||
</array>
|
</array>
|
||||||
<key>IBSystem Version</key>
|
<key>IBSystem Version</key>
|
||||||
<string>9A283</string>
|
<string>9A283</string>
|
||||||
|
|
BIN
English.lproj/MainMenu.nib/keyedobjects.nib
generated
BIN
English.lproj/MainMenu.nib/keyedobjects.nib
generated
Binary file not shown.
|
@ -4,6 +4,8 @@
|
||||||
<dict>
|
<dict>
|
||||||
<key>VLHighPitch</key>
|
<key>VLHighPitch</key>
|
||||||
<integer>75</integer>
|
<integer>75</integer>
|
||||||
|
<key>VLLilypondPath</key>
|
||||||
|
<string>/sw/bin/lilypond</string>
|
||||||
<key>VLLowPitch</key>
|
<key>VLLowPitch</key>
|
||||||
<integer>57</integer>
|
<integer>57</integer>
|
||||||
</dict>
|
</dict>
|
||||||
|
|
|
@ -9,9 +9,17 @@
|
||||||
#import <Cocoa/Cocoa.h>
|
#import <Cocoa/Cocoa.h>
|
||||||
|
|
||||||
@interface VLAppController : NSObject {
|
@interface VLAppController : NSObject {
|
||||||
|
IBOutlet id lilypondPath;
|
||||||
|
|
||||||
|
NSString * toolPath;
|
||||||
|
NSString * appPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (IBAction) playNewPitch:(id)sender;
|
- (IBAction) playNewPitch:(id)sender;
|
||||||
|
- (IBAction) selectLilypondPath:(id)sender;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
// Local Variables:
|
||||||
|
// mode:ObjC
|
||||||
|
// End:
|
||||||
|
|
|
@ -53,6 +53,110 @@
|
||||||
[self setupTransformers];
|
[self setupTransformers];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (id)init
|
||||||
|
{
|
||||||
|
if (self = [super init]) {
|
||||||
|
toolPath = nil;
|
||||||
|
appPath = nil;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString*)getLineFromCommand:(NSString*)command
|
||||||
|
{
|
||||||
|
char line[1000];
|
||||||
|
FILE * output = popen([command UTF8String], "r");
|
||||||
|
if (fgets(line, 1000, output)) {
|
||||||
|
fprintf(stderr, "Line %s", line);
|
||||||
|
size_t len = strlen(line);
|
||||||
|
if (len && line[len-1]=='\n') {
|
||||||
|
line[len-1] = 0;
|
||||||
|
return [NSString stringWithUTF8String:line];
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
NSLog(@"Failed command: %@ (%d)\n", command, errno);
|
||||||
|
pclose(output);
|
||||||
|
return nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (NSString *)lilypondVersion:(NSString *)path
|
||||||
|
{
|
||||||
|
NSString * cmd =
|
||||||
|
[NSString stringWithFormat:
|
||||||
|
@"%@ --version | awk '{ print $3 }'",
|
||||||
|
path];
|
||||||
|
return [self getLineFromCommand:cmd];
|
||||||
|
}
|
||||||
|
|
||||||
|
- (void)awakeFromNib
|
||||||
|
{
|
||||||
|
[lilypondPath setAutoenablesItems:NO];
|
||||||
|
|
||||||
|
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
||||||
|
NSFileManager * fileManager = [NSFileManager defaultManager];
|
||||||
|
NSString * lilyPath = [defaults stringForKey:@"VLLilypondPath"];
|
||||||
|
NSRange app = [lilyPath rangeOfString:@".app"];
|
||||||
|
bool wantTool = app.location == NSNotFound;
|
||||||
|
|
||||||
|
if ([fileManager isExecutableFileAtPath:lilyPath]) {
|
||||||
|
//
|
||||||
|
// Path still valid, figure out what it is
|
||||||
|
//
|
||||||
|
if (wantTool)
|
||||||
|
toolPath = lilyPath;
|
||||||
|
else
|
||||||
|
appPath = lilyPath;
|
||||||
|
}
|
||||||
|
if (!appPath)
|
||||||
|
appPath =
|
||||||
|
[[[NSWorkspace sharedWorkspace]
|
||||||
|
absolutePathForAppBundleWithIdentifier:@"org.lilypond.lilypond"]
|
||||||
|
stringByAppendingPathComponent:@"Contents/Resources/bin/lilypond"];
|
||||||
|
if (!toolPath)
|
||||||
|
toolPath = [self getLineFromCommand:@"bash -l which lilypond"];
|
||||||
|
|
||||||
|
NSString * appVersion = nil;
|
||||||
|
NSString * toolVersion = nil;
|
||||||
|
|
||||||
|
if (appPath) {
|
||||||
|
appVersion = [self lilypondVersion:appPath];
|
||||||
|
if (!appVersion)
|
||||||
|
appPath = nil;
|
||||||
|
}
|
||||||
|
if (toolPath) {
|
||||||
|
toolVersion = [self lilypondVersion:toolPath];
|
||||||
|
if (!toolVersion)
|
||||||
|
toolPath = nil;
|
||||||
|
}
|
||||||
|
|
||||||
|
NSMenuItem * toolItem = [lilypondPath itemAtIndex:0];
|
||||||
|
NSMenuItem * appItem = [lilypondPath itemAtIndex:1];
|
||||||
|
|
||||||
|
if (toolPath) {
|
||||||
|
[toolItem setTitle:
|
||||||
|
[NSString stringWithFormat:@"%@ (%@)", toolPath, toolVersion]];
|
||||||
|
} else {
|
||||||
|
[toolItem setTitle:@"lilypond tool not installed"];
|
||||||
|
[toolItem setEnabled:NO];
|
||||||
|
}
|
||||||
|
if (appPath) {
|
||||||
|
NSRange r = [appPath rangeOfString:@"/Contents/Resources"];
|
||||||
|
[appItem setTitle:
|
||||||
|
[NSString stringWithFormat:@"%@ (%@)",
|
||||||
|
[appPath substringToIndex:r.location], appVersion]];
|
||||||
|
} else {
|
||||||
|
[appItem setTitle:@"Lilypond.app not installed"];
|
||||||
|
[appItem setEnabled:NO];
|
||||||
|
}
|
||||||
|
if (!toolPath && appPath) {
|
||||||
|
wantTool = false;
|
||||||
|
[defaults setObject:appPath forKey:@"VLLilypondPath"];
|
||||||
|
} else if (toolPath && !appPath) {
|
||||||
|
wantTool = true;
|
||||||
|
[defaults setObject:toolPath forKey:@"VLLilypondPath"];
|
||||||
|
}
|
||||||
|
[lilypondPath selectItemWithTag:wantTool ? 0 : 1];
|
||||||
|
}
|
||||||
|
|
||||||
- (IBAction) playNewPitch:(id)sender
|
- (IBAction) playNewPitch:(id)sender
|
||||||
{
|
{
|
||||||
VLNote note(VLFraction(1,4), [sender intValue]);
|
VLNote note(VLFraction(1,4), [sender intValue]);
|
||||||
|
@ -60,4 +164,20 @@
|
||||||
VLSoundOut::Instance()->PlayNote(note);
|
VLSoundOut::Instance()->PlayNote(note);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (IBAction) selectLilypondPath:(id)sender
|
||||||
|
{
|
||||||
|
NSUserDefaults* defaults = [NSUserDefaults standardUserDefaults];
|
||||||
|
|
||||||
|
switch ([sender tag]) {
|
||||||
|
case 0:
|
||||||
|
[defaults setObject:toolPath forKey:@"VLLilypondPath"];
|
||||||
|
break;
|
||||||
|
case 1:
|
||||||
|
[defaults setObject:toolPath forKey:@"VLLilypondPath"];
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Reference in New Issue
Block a user