-
Notifications
You must be signed in to change notification settings - Fork 0
/
PSSessionDocument.mm
126 lines (100 loc) · 3.29 KB
/
PSSessionDocument.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
//
// PSSessionDocument.mm
// Gusto
//
// Created by Taybin Rutkin on 2/20/07.
// Copyright Penguin Sounds 2007 . All rights reserved.
//
#include <sigc++/sigc++.h>
#include <ardour/configuration.h>
#include <ardour/session.h>
#include <ardour/route.h>
#include <ardour/audioengine.h>
#import "PSAppController.h"
#import "PSNewDialogController.h"
#import "PSSessionDocument.h"
#import "PSAddTrack.h"
#import "PSEditorTrack.h"
#import "PSEditorWindowController.h"
#import "PSMixerWindowController.h"
#include "objcsigcglue.h"
@implementation PSSessionDocument
- (id)init
{
self = [super init];
if (self) {
sess = 0;
}
return self;
}
- (void) dealloc {
delete sess;
[super dealloc];
}
- (void)makeWindowControllers
{
PSEditorWindowController *editor = [[PSEditorWindowController alloc] initWithSession:sess];
[self addWindowController:editor];
PSMixerWindowController *mixer = [[PSMixerWindowController alloc] initWithSession:sess];
[self addWindowController:mixer];
[mixer showWindow:self];
}
- (void)windowControllerDidLoadNib:(NSWindowController *) aController
{
[super windowControllerDidLoadNib:aController];
// Add any code here that needs to be executed once the windowController has loaded the document's window.
}
- (BOOL)writeToURL:(NSURL *)absoluteURL ofType:(NSString *)typeName forSaveOperation:(NSSaveOperationType)saveOperation originalContentsURL:(NSURL *)absoluteOriginalContentsURL error:(NSError **)outError
{
NSLog(@"writeToURL. NOT REACHED");
return YES;
}
- (void)saveSession
{
sess->save_state ([[[[self fileURL] path] lastPathComponent] UTF8String]);
[self updateChangeCount:NSChangeCleared];
}
- (BOOL)readFromURL:(NSURL *)absoluteURL ofType:(NSString *)typeName error:(NSError **)outError
{
// Insert code here to read your document from the given data of the specified type. If the given outError != NULL, ensure that you set *outError when returning NO.
NSLog([absoluteURL path]);
ARDOUR::AudioEngine *eng = [[PSAppController sharedManager] engine];
try {
sess = new ARDOUR::Session (*eng, [[absoluteURL path] fileSystemRepresentation], [[[absoluteURL path] lastPathComponent] UTF8String], 0);
} catch (...) {
NSLog(@"Session did not load correctly");
return NO;
}
return YES;
}
- (IBAction)addTrack:(id)sender
{
PSAddTrack *at = [[PSAppController sharedManager] addTrackController];
[at doit:self];
}
- (void)tracksAdded
{
PSAddTrack *at = [[PSAppController sharedManager] addTrackController];
uint32_t input_chan = [at inputChannels];
uint32_t output_chan;
ARDOUR::AutoConnectOption oac = ARDOUR::Config->get_output_auto_connect();
if (oac & ARDOUR::AutoConnectMaster) {
output_chan = (sess->master_out() ? sess->master_out()->n_inputs() : input_chan);
}
try {
if ([at track]) {
sess->new_audio_track (input_chan, output_chan, [at mode], [at nTracks]);
} else {
sess->new_audio_route (input_chan, output_chan, [at nTracks]);
}
} catch (...) {
// TODO can we automate this?
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:@"OK"];
[alert setMessageText:@"Could not create all tracks/busses"];
[alert setInformativeText:@"Save your session, exit, and try to restart Jack with more ports"];
[alert setAlertStyle:NSWarningAlertStyle];
}
[self updateChangeCount:NSChangeDone];
}
@end