Skip to content

Commit

Permalink
Cleaning up code
Browse files Browse the repository at this point in the history
  • Loading branch information
SteffeyDev committed Feb 25, 2020
1 parent e1888d0 commit 7969e5b
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 87 deletions.
1 change: 0 additions & 1 deletion atemOSC/AppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
@property (readonly) std::map<BMDSwitcherHyperDeckId, IBMDSwitcherHyperDeck*> mHyperdecks;
@property (readonly) std::map<BMDSwitcherHyperDeckId, HyperDeckMonitor*> mHyperdeckMonitors;
@property (readonly) std::vector<IBMDSwitcherInputAux*> mSwitcherInputAuxList;
@property (readonly) IBMDSwitcherStills* mStills;
@property (readonly) IBMDSwitcherInputSuperSource* mSuperSource;
@property (readonly) IBMDSwitcherMacroPool* mMacroPool;
@property (readonly) IBMDSwitcherMacroControl* mMacroControl;
Expand Down
185 changes: 100 additions & 85 deletions atemOSC/AppDelegate.mm
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ @implementation AppDelegate
@synthesize switcherTransitionParameters;
@synthesize mMediaPool;
@synthesize mMediaPlayers;
@synthesize mStills;
@synthesize mMacroPool;
@synthesize mSuperSource;
@synthesize mMacroControl;
Expand All @@ -63,42 +62,23 @@ @implementation AppDelegate

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSMenu* edit = [[[[NSApplication sharedApplication] mainMenu] itemWithTitle: @"Edit"] submenu];
if ([[edit itemAtIndex: [edit numberOfItems] - 1] action] == NSSelectorFromString(@"orderFrontCharacterPalette:"))
[edit removeItemAtIndex: [edit numberOfItems] - 1];
if ([[edit itemAtIndex: [edit numberOfItems] - 1] action] == NSSelectorFromString(@"startDictation:"))
[edit removeItemAtIndex: [edit numberOfItems] - 1];
if ([[edit itemAtIndex: [edit numberOfItems] - 1] isSeparatorItem])
[edit removeItemAtIndex: [edit numberOfItems] - 1];
[self setupMenu];

mSwitcherDiscovery = NULL;
mSwitcher = NULL;
mMixEffectBlock = NULL;
mMediaPool = NULL;
mMacroPool = NULL;
mSuperSource = NULL;
mMacroControl = NULL;
mAudioMixer = NULL;

isConnectedToATEM = NO;

endpoints = [[NSMutableArray alloc] init];
mOscReceiver = [[OSCReceiver alloc] initWithDelegate:self];

mSwitcherMonitor = new SwitcherMonitor(self);
mMonitors.push_back(mSwitcherMonitor);
mDownstreamKeyerMonitor = new DownstreamKeyerMonitor(self);
mMonitors.push_back(mDownstreamKeyerMonitor);
mUpstreamKeyerMonitor = new UpstreamKeyerMonitor(self);
mMonitors.push_back(mUpstreamKeyerMonitor);
mUpstreamKeyerLumaParametersMonitor = new UpstreamKeyerLumaParametersMonitor(self);
mMonitors.push_back(mUpstreamKeyerLumaParametersMonitor);
mUpstreamKeyerChromaParametersMonitor = new UpstreamKeyerChromaParametersMonitor(self);
mMonitors.push_back(mUpstreamKeyerChromaParametersMonitor);
mTransitionParametersMonitor = new TransitionParametersMonitor(self);
mMonitors.push_back(mTransitionParametersMonitor);
mMixEffectBlockMonitor = new MixEffectBlockMonitor(self);
mMonitors.push_back(mMixEffectBlockMonitor);
mMacroPoolMonitor = new MacroPoolMonitor(self);
mMonitors.push_back(mMacroPoolMonitor);
mAudioMixerMonitor = new AudioMixerMonitor(self);
mMonitors.push_back(mAudioMixerMonitor);
[self setupMonitors];

[logTextView setTextColor:[NSColor whiteColor]];

Expand Down Expand Up @@ -131,6 +111,44 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
[self portChanged:incomingPort out:outgoingPort ip:outIpStr];
}

[self checkForUpdate];
}

- (void)setupMenu
{
NSMenu* edit = [[[[NSApplication sharedApplication] mainMenu] itemWithTitle: @"Edit"] submenu];
if ([[edit itemAtIndex: [edit numberOfItems] - 1] action] == NSSelectorFromString(@"orderFrontCharacterPalette:"))
[edit removeItemAtIndex: [edit numberOfItems] - 1];
if ([[edit itemAtIndex: [edit numberOfItems] - 1] action] == NSSelectorFromString(@"startDictation:"))
[edit removeItemAtIndex: [edit numberOfItems] - 1];
if ([[edit itemAtIndex: [edit numberOfItems] - 1] isSeparatorItem])
[edit removeItemAtIndex: [edit numberOfItems] - 1];
}

- (void)setupMonitors
{
mSwitcherMonitor = new SwitcherMonitor(self);
mMonitors.push_back(mSwitcherMonitor);
mDownstreamKeyerMonitor = new DownstreamKeyerMonitor(self);
mMonitors.push_back(mDownstreamKeyerMonitor);
mUpstreamKeyerMonitor = new UpstreamKeyerMonitor(self);
mMonitors.push_back(mUpstreamKeyerMonitor);
mUpstreamKeyerLumaParametersMonitor = new UpstreamKeyerLumaParametersMonitor(self);
mMonitors.push_back(mUpstreamKeyerLumaParametersMonitor);
mUpstreamKeyerChromaParametersMonitor = new UpstreamKeyerChromaParametersMonitor(self);
mMonitors.push_back(mUpstreamKeyerChromaParametersMonitor);
mTransitionParametersMonitor = new TransitionParametersMonitor(self);
mMonitors.push_back(mTransitionParametersMonitor);
mMixEffectBlockMonitor = new MixEffectBlockMonitor(self);
mMonitors.push_back(mMixEffectBlockMonitor);
mMacroPoolMonitor = new MacroPoolMonitor(self);
mMonitors.push_back(mMacroPoolMonitor);
mAudioMixerMonitor = new AudioMixerMonitor(self);
mMonitors.push_back(mAudioMixerMonitor);
}

- (void)checkForUpdate
{
// Check if new version available
NSError *error = nil;
NSString *url_string = [NSString stringWithFormat: @"https://api.github.com/repos/danielbuechele/atemOSC/releases/latest"];
Expand Down Expand Up @@ -287,10 +305,27 @@ - (void)switcherConnected
if (SUCCEEDED(mSwitcher->CreateIterator(IID_IBMDSwitcherMixEffectBlockIterator, (void**)&iterator)))
{
// Use the first Mix Effect Block
if (S_OK != iterator->Next(&mMixEffectBlock))
if (S_OK == iterator->Next(&mMixEffectBlock))
{
mMixEffectBlock->AddCallback(mMixEffectBlockMonitor);
mMixEffectBlockMonitor->updateSliderPosition();

if (SUCCEEDED(mMixEffectBlock->QueryInterface(IID_IBMDSwitcherTransitionParameters, (void**)&switcherTransitionParameters)))
{
switcherTransitionParameters->AddCallback(mTransitionParametersMonitor);
}
else
{
[self logMessage:@"Could not get IBMDSwitcherTransitionParameters"];
}

}
else
{
[self logMessage:@"Could not get the first IBMDSwitcherMixEffectBlock"];
}

iterator->Release();
}
else
{
Expand Down Expand Up @@ -475,16 +510,6 @@ - (void)switcherConnected
{
[self logMessage:[NSString stringWithFormat:@"Could not create IBMDSwitcherAudioInputIterator iterator. code: %d", HRESULT_CODE(result)]];
}

switcherTransitionParameters = NULL;
if (mMixEffectBlock)
{
mMixEffectBlock->QueryInterface(IID_IBMDSwitcherTransitionParameters, (void**)&switcherTransitionParameters);
switcherTransitionParameters->AddCallback(mTransitionParametersMonitor);
mMixEffectBlock->AddCallback(mMixEffectBlockMonitor);
}

self->mMixEffectBlockMonitor->updateSliderPosition();

// Hyperdeck Setup
IBMDSwitcherHyperDeckIterator* hyperDeckIterator = NULL;
Expand Down Expand Up @@ -512,10 +537,6 @@ - (void)switcherConnected
dispatch_async(dispatch_get_main_queue(), ^{
[helpPanel setupWithDelegate: self];
});

finish:
if (iterator)
iterator->Release();
}

- (void)switcherDisconnected
Expand Down Expand Up @@ -547,34 +568,38 @@ - (void)switcherDisconnected

- (void)cleanUpConnection
{
while (mSwitcherInputAuxList.size())
if (mSwitcher)
{
mSwitcherInputAuxList.back()->Release();
mSwitcherInputAuxList.pop_back();
mSwitcher->RemoveCallback(mSwitcherMonitor);
mSwitcher->Release();
mSwitcher = NULL;
}

while (mMediaPlayers.size())
if (mMixEffectBlock)
{
mMediaPlayers.back()->Release();
mMediaPlayers.pop_back();
mMixEffectBlock->RemoveCallback(mMixEffectBlockMonitor);
mMixEffectBlock->Release();
mMixEffectBlock = NULL;
}

if (mStills)
if (switcherTransitionParameters)
{
mStills->Release();
mStills = NULL;
switcherTransitionParameters->RemoveCallback(mTransitionParametersMonitor);
switcherTransitionParameters->Release();
switcherTransitionParameters = NULL;
}

if (mMediaPool)
for (auto const& it : mInputs)
{
mMediaPool->Release();
mMediaPool = NULL;
it.second->RemoveCallback(mInputMonitors.at(it.first));
it.second->Release();
}
mInputs.clear();

while (mSuperSourceBoxes.size())
while (mSwitcherInputAuxList.size())
{
mSuperSourceBoxes.back()->Release();
mSuperSourceBoxes.pop_back();
mSwitcherInputAuxList.back()->Release();
mSwitcherInputAuxList.pop_back();
}

while (keyers.size())
Expand All @@ -599,18 +624,16 @@ - (void)cleanUpConnection
dsk.pop_back();
}

if (mMixEffectBlock)
while (mMediaPlayers.size())
{
mMixEffectBlock->RemoveCallback(mMixEffectBlockMonitor);
mMixEffectBlock->Release();
mMixEffectBlock = NULL;
mMediaPlayers.back()->Release();
mMediaPlayers.pop_back();
}

if (mSwitcher)
if (mMediaPool)
{
mSwitcher->RemoveCallback(mSwitcherMonitor);
mSwitcher->Release();
mSwitcher = NULL;
mMediaPool->Release();
mMediaPool = NULL;
}

if (mMacroPool)
Expand All @@ -620,40 +643,32 @@ - (void)cleanUpConnection
mMacroPool = NULL;
}

for (auto const& it : mAudioInputs)
while (mSuperSourceBoxes.size())
{
it.second->RemoveCallback(mAudioInputMonitors.at(it.first));
it.second->Release();
mSuperSourceBoxes.back()->Release();
mSuperSourceBoxes.pop_back();
}
mAudioInputs.clear();

for (auto const& it : mInputs)
if (mAudioMixer)
{
it.second->RemoveCallback(mInputMonitors.at(it.first));
mAudioMixer->RemoveCallback(mAudioMixerMonitor);
mAudioMixer->Release();
mAudioMixer = NULL;
}

for (auto const& it : mAudioInputs)
{
it.second->RemoveCallback(mAudioInputMonitors.at(it.first));
it.second->Release();
}
mInputs.clear();
mAudioInputs.clear();

for (auto const& it : mHyperdecks)
{
it.second->RemoveCallback(mHyperdeckMonitors.at(it.first));
it.second->Release();
}
mHyperdecks.clear();

if (mAudioMixer)
{
mAudioMixer->RemoveCallback(mAudioMixerMonitor);
mAudioMixer->Release();
mAudioMixer = NULL;
}

if (switcherTransitionParameters)
{
switcherTransitionParameters->RemoveCallback(mTransitionParametersMonitor);
switcherTransitionParameters->Release();
switcherTransitionParameters = NULL;
}
}

// We run this recursively so that we can get the
Expand Down
2 changes: 1 addition & 1 deletion atemOSC/English.lproj/MainMenu.xib
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<clipView key="contentView" ambiguous="YES" drawsBackground="NO" copiesOnScroll="NO" id="Ehi-52-hIa">
<rect key="frame" x="0.0" y="0.0" width="373" height="272"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textView ambiguous="YES" editable="NO" drawsBackground="NO" importsGraphics="NO" verticallyResizable="YES" usesFontPanel="YES" findStyle="panel" usesRuler="YES" allowsNonContiguousLayout="YES" spellingCorrection="YES" id="yea-mf-8MA">
<rect key="frame" x="0.0" y="0.0" width="373" height="272"/>
Expand Down
7 changes: 7 additions & 0 deletions atemOSC/OSCReceiver.mm
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,13 @@ - (instancetype) initWithDelegate:(AppDelegate *) delegate
return false;
} copy] forKey:@"/atem/audio/input"];

[validators setObject:[^bool(NSDictionary *d, OSCValue *v) {
if ([appDel mAudioMixer])
return true;
[appDel logMessage:@"No audio mixer"];
return false;
} copy] forKey:@"/atem/audio/output"];

[validators setObject:[^bool(NSDictionary *d, OSCValue *v) {
int mplayer = [[d objectForKey:@"<player>"] intValue];

Expand Down

0 comments on commit 7969e5b

Please sign in to comment.