Permalink
Browse files

Initial commit

  • Loading branch information...
0 parents commit b17d736382e1032898cf582543080f88573fe734 @kyleneideck committed Feb 19, 2016
Showing with 30,137 additions and 0 deletions.
  1. +30 −0 .gitignore
  2. +25 −0 BGM.xcworkspace/contents.xcworkspacedata
  3. +808 −0 BGMApp/BGMApp.xcodeproj/project.pbxproj
  4. +37 −0 BGMApp/BGMApp/AppDelegate.h
  5. +144 −0 BGMApp/BGMApp/AppDelegate.mm
  6. +57 −0 BGMApp/BGMApp/BGMAppVolumes.h
  7. +298 −0 BGMApp/BGMApp/BGMAppVolumes.mm
  8. +53 −0 BGMApp/BGMApp/BGMAudioDeviceManager.h
  9. +215 −0 BGMApp/BGMApp/BGMAudioDeviceManager.mm
  10. +40 −0 BGMApp/BGMApp/BGMAutoPauseMusic.h
  11. +187 −0 BGMApp/BGMApp/BGMAutoPauseMusic.mm
  12. +355 −0 BGMApp/BGMApp/BGMDeviceControlSync.cpp
  13. +81 −0 BGMApp/BGMApp/BGMDeviceControlSync.h
  14. +662 −0 BGMApp/BGMApp/BGMPlayThrough.cpp
  15. +140 −0 BGMApp/BGMApp/BGMPlayThrough.h
  16. +197 −0 BGMApp/BGMApp/Base.lproj/MainMenu.xib
  17. +68 −0 BGMApp/BGMApp/Images.xcassets/AppIcon.appiconset/Contents.json
  18. BIN BGMApp/BGMApp/Images.xcassets/AppIcon.appiconset/appicon_1024.png
  19. BIN BGMApp/BGMApp/Images.xcassets/AppIcon.appiconset/appicon_128.png
  20. BIN BGMApp/BGMApp/Images.xcassets/AppIcon.appiconset/appicon_16.png
  21. BIN BGMApp/BGMApp/Images.xcassets/AppIcon.appiconset/appicon_256.png
  22. BIN BGMApp/BGMApp/Images.xcassets/AppIcon.appiconset/appicon_32.png
  23. BIN BGMApp/BGMApp/Images.xcassets/AppIcon.appiconset/appicon_512.png
  24. BIN BGMApp/BGMApp/Images.xcassets/AppIcon.appiconset/appicon_64.png
  25. +6 −0 BGMApp/BGMApp/Images.xcassets/Contents.json
  26. +12 −0 BGMApp/BGMApp/Images.xcassets/FermataIcon.imageset/Contents.json
  27. BIN BGMApp/BGMApp/Images.xcassets/FermataIcon.imageset/FermataIcon.pdf
  28. +38 −0 BGMApp/BGMApp/Info.plist
  29. +339 −0 BGMApp/BGMApp/LICENSE
  30. +106 −0 BGMApp/BGMApp/Music Players/BGMMusicPlayer.h
  31. +67 −0 BGMApp/BGMApp/Music Players/BGMMusicPlayer.m
  32. +30 −0 BGMApp/BGMApp/Music Players/BGMSpotify.h
  33. +101 −0 BGMApp/BGMApp/Music Players/BGMSpotify.m
  34. +31 −0 BGMApp/BGMApp/Music Players/BGMiTunes.h
  35. +103 −0 BGMApp/BGMApp/Music Players/BGMiTunes.m
  36. +40 −0 BGMApp/BGMApp/Preferences/BGMAutoPauseMusicPrefs.h
  37. +205 −0 BGMApp/BGMApp/Preferences/BGMAutoPauseMusicPrefs.mm
  38. +36 −0 BGMApp/BGMApp/Preferences/BGMOutputDevicePrefs.h
  39. +107 −0 BGMApp/BGMApp/Preferences/BGMOutputDevicePrefs.mm
  40. +45 −0 BGMApp/BGMApp/Preferences/BGMPreferencesMenu.h
  41. +131 −0 BGMApp/BGMApp/Preferences/BGMPreferencesMenu.mm
  42. +82 −0 BGMApp/BGMApp/Spotify.h
  43. +528 −0 BGMApp/BGMApp/iTunes.h
  44. +29 −0 BGMApp/BGMApp/main.m
  45. +58 −0 BGMApp/BGMAppTests/BGMAppTests.m
  46. +24 −0 BGMApp/BGMAppTests/Info.plist
  47. BIN BGMApp/OptimizationProfiles/BGMApp.profdata
  48. +305 −0 BGMApp/PublicUtility/CAAtomic.h
  49. +508 −0 BGMApp/PublicUtility/CAAutoDisposer.h
  50. +206 −0 BGMApp/PublicUtility/CABitOperations.h
  51. +821 −0 BGMApp/PublicUtility/CACFArray.cpp
  52. +195 −0 BGMApp/PublicUtility/CACFArray.h
  53. +581 −0 BGMApp/PublicUtility/CACFDictionary.cpp
  54. +176 −0 BGMApp/PublicUtility/CACFDictionary.h
  55. +83 −0 BGMApp/PublicUtility/CACFNumber.cpp
  56. +151 −0 BGMApp/PublicUtility/CACFNumber.h
  57. +110 −0 BGMApp/PublicUtility/CACFString.cpp
  58. +196 −0 BGMApp/PublicUtility/CACFString.h
  59. +90 −0 BGMApp/PublicUtility/CADebugMacros.cpp
  60. +581 −0 BGMApp/PublicUtility/CADebugMacros.h
  61. +89 −0 BGMApp/PublicUtility/CADebugPrintf.cpp
  62. +115 −0 BGMApp/PublicUtility/CADebugPrintf.h
  63. +103 −0 BGMApp/PublicUtility/CADebugger.cpp
  64. +69 −0 BGMApp/PublicUtility/CADebugger.h
  65. +83 −0 BGMApp/PublicUtility/CAException.h
  66. +1,156 −0 BGMApp/PublicUtility/CAHALAudioDevice.cpp
  67. +238 −0 BGMApp/PublicUtility/CAHALAudioDevice.h
  68. +370 −0 BGMApp/PublicUtility/CAHALAudioObject.cpp
  69. +155 −0 BGMApp/PublicUtility/CAHALAudioObject.h
  70. +182 −0 BGMApp/PublicUtility/CAHALAudioStream.cpp
  71. +94 −0 BGMApp/PublicUtility/CAHALAudioStream.h
  72. +181 −0 BGMApp/PublicUtility/CAHALAudioSystemObject.cpp
  73. +90 −0 BGMApp/PublicUtility/CAHALAudioSystemObject.h
  74. +99 −0 BGMApp/PublicUtility/CAHostTimeBase.cpp
  75. +234 −0 BGMApp/PublicUtility/CAHostTimeBase.h
  76. +345 −0 BGMApp/PublicUtility/CAMutex.cpp
  77. +163 −0 BGMApp/PublicUtility/CAMutex.h
  78. +450 −0 BGMApp/PublicUtility/CAPThread.cpp
  79. +191 −0 BGMApp/PublicUtility/CAPThread.h
  80. +312 −0 BGMApp/PublicUtility/CAPropertyAddress.h
  81. +319 −0 BGMApp/PublicUtility/CARingBuffer.cpp
  82. +126 −0 BGMApp/PublicUtility/CARingBuffer.h
  83. +678 −0 BGMDriver/BGMDriver.xcodeproj/project.pbxproj
  84. +2,342 −0 BGMDriver/BGMDriver/BGM_Device.cpp
  85. +224 −0 BGMDriver/BGMDriver/BGM_Device.h
  86. +188 −0 BGMDriver/BGMDriver/BGM_Object.cpp
  87. +162 −0 BGMDriver/BGMDriver/BGM_Object.h
  88. +220 −0 BGMDriver/BGMDriver/BGM_PlugIn.cpp
  89. +87 −0 BGMDriver/BGMDriver/BGM_PlugIn.h
  90. +812 −0 BGMDriver/BGMDriver/BGM_PlugInInterface.cpp
  91. +461 −0 BGMDriver/BGMDriver/BGM_TaskQueue.cpp
  92. +196 −0 BGMDriver/BGMDriver/BGM_TaskQueue.h
  93. +162 −0 BGMDriver/BGMDriver/BGM_Types.h
  94. +45 −0 BGMDriver/BGMDriver/BGM_WrappedAudioEngine.cpp
  95. +48 −0 BGMDriver/BGMDriver/BGM_WrappedAudioEngine.h
  96. +52 −0 BGMDriver/BGMDriver/DeviceClients/BGM_Client.cpp
  97. +80 −0 BGMDriver/BGMDriver/DeviceClients/BGM_Client.h
  98. +359 −0 BGMDriver/BGMDriver/DeviceClients/BGM_ClientMap.cpp
  99. +174 −0 BGMDriver/BGMDriver/DeviceClients/BGM_ClientMap.h
  100. +56 −0 BGMDriver/BGMDriver/DeviceClients/BGM_ClientTasks.h
  101. +359 −0 BGMDriver/BGMDriver/DeviceClients/BGM_Clients.cpp
  102. +142 −0 BGMDriver/BGMDriver/DeviceClients/BGM_Clients.h
  103. BIN BGMDriver/BGMDriver/DeviceIcon.icns
  104. +38 −0 BGMDriver/BGMDriver/Info.plist
  105. +211 −0 BGMDriver/BGMDriver/quick_install.sh
  106. +224 −0 BGMDriver/BGMDriverTests/BGM_ClientMapTests.mm
  107. +130 −0 BGMDriver/BGMDriverTests/BGM_ClientsTests.mm
  108. +55 −0 BGMDriver/BGMDriverTests/BGM_DeviceTests.mm
  109. +46 −0 BGMDriver/BGMDriverTests/BGM_TestUtils.h
  110. +24 −0 BGMDriver/BGMDriverTests/Info.plist
  111. +305 −0 BGMDriver/PublicUtility/CAAtomic.h
  112. +239 −0 BGMDriver/PublicUtility/CAAtomicStack.h
  113. +508 −0 BGMDriver/PublicUtility/CAAutoDisposer.h
  114. +821 −0 BGMDriver/PublicUtility/CACFArray.cpp
  115. +195 −0 BGMDriver/PublicUtility/CACFArray.h
  116. +581 −0 BGMDriver/PublicUtility/CACFDictionary.cpp
  117. +176 −0 BGMDriver/PublicUtility/CACFDictionary.h
  118. +83 −0 BGMDriver/PublicUtility/CACFNumber.cpp
  119. +151 −0 BGMDriver/PublicUtility/CACFNumber.h
  120. +110 −0 BGMDriver/PublicUtility/CACFString.cpp
  121. +180 −0 BGMDriver/PublicUtility/CACFString.h
  122. +90 −0 BGMDriver/PublicUtility/CADebugMacros.cpp
  123. +581 −0 BGMDriver/PublicUtility/CADebugMacros.h
  124. +89 −0 BGMDriver/PublicUtility/CADebugPrintf.cpp
  125. +115 −0 BGMDriver/PublicUtility/CADebugPrintf.h
  126. +103 −0 BGMDriver/PublicUtility/CADebugger.cpp
  127. +69 −0 BGMDriver/PublicUtility/CADebugger.h
  128. +438 −0 BGMDriver/PublicUtility/CADispatchQueue.cpp
  129. +235 −0 BGMDriver/PublicUtility/CADispatchQueue.h
  130. +83 −0 BGMDriver/PublicUtility/CAException.h
  131. +99 −0 BGMDriver/PublicUtility/CAHostTimeBase.cpp
  132. +234 −0 BGMDriver/PublicUtility/CAHostTimeBase.h
  133. +345 −0 BGMDriver/PublicUtility/CAMutex.cpp
  134. +164 −0 BGMDriver/PublicUtility/CAMutex.h
  135. +450 −0 BGMDriver/PublicUtility/CAPThread.cpp
  136. +191 −0 BGMDriver/PublicUtility/CAPThread.h
  137. +482 −0 BGMDriver/PublicUtility/CAVolumeCurve.cpp
  138. +178 −0 BGMDriver/PublicUtility/CAVolumeCurve.h
  139. +22 −0 CONTRIBUTING.md
  140. +148 −0 DEVELOPING.md
  141. BIN Images/FermataIcon.pdf
  142. +63 −0 Images/FermataIcon.tex
  143. BIN Images/README/FermataIcon.png
  144. BIN Images/README/Screenshot.png
  145. +86 −0 Images/generate_icon_pngs.sh
  146. +38 −0 Images/iconizer.sh
  147. BIN LICENSE
  148. +129 −0 README.md
  149. +99 −0 TODO.md
@@ -0,0 +1,30 @@
+.DS_Store
+.*.swp
+/BGMDriver/BGMDriver/quick_install.conf
+
+# Everything below is from https://github.com/github/gitignore/blob/master/Objective-C.gitignore
+
+## Build generated
+build/
+DerivedData
+
+## Various settings
+*.pbxuser
+!default.pbxuser
+*.mode1v3
+!default.mode1v3
+*.mode2v3
+!default.mode2v3
+*.perspectivev3
+!default.perspectivev3
+xcuserdata
+
+## Other
+*.xccheckout
+*.moved-aside
+*.xcuserstate
+*.xcscmblueprint
+
+## Obj-C/Swift specific
+*.hmap
+*.ipa

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,37 @@
+// This file is part of Background Music.
+//
+// Background Music is free software: you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation, either version 2 of the
+// License, or (at your option) any later version.
+//
+// Background Music is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Background Music. If not, see <http://www.gnu.org/licenses/>.
+
+//
+// AppDelegate.h
+// BGMApp
+//
+// Copyright © 2016 Kyle Neideck
+//
+// Sets up and tears down the app.
+//
+
+#import <Cocoa/Cocoa.h>
+
+
+@interface AppDelegate : NSObject <NSApplicationDelegate>
+
+@property (weak) IBOutlet NSMenu* bgmMenu;
+@property (weak) IBOutlet NSMenuItem* autoPauseMenuItem;
+@property (weak) IBOutlet NSView* appVolumeView;
+@property (weak) IBOutlet NSPanel* aboutPanel;
+@property (unsafe_unretained) IBOutlet NSTextView *aboutPanelLicenseView;
+
+@end
+
@@ -0,0 +1,144 @@
+// This file is part of Background Music.
+//
+// Background Music is free software: you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation, either version 2 of the
+// License, or (at your option) any later version.
+//
+// Background Music is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Background Music. If not, see <http://www.gnu.org/licenses/>.
+
+//
+// AppDelegate.mm
+// BGMApp
+//
+// Copyright © 2016 Kyle Neideck
+//
+
+// Self Includes
+#import "AppDelegate.h"
+
+// Local Includes
+#include "BGM_Types.h"
+#import "BGMAudioDeviceManager.h"
+#import "BGMAutoPauseMusic.h"
+#import "BGMAppVolumes.h"
+#import "BGMPreferencesMenu.h"
+
+
+static float const kStatusBarIconPadding = 0.25;
+
+@implementation AppDelegate {
+ // The button in the system status bar (the bar with volume, battery, clock, etc.) to show the main menu
+ // for the app. These are called "menu bar extras" in the Human Interface Guidelines.
+ NSStatusItem* statusBarItem;
+
+ BGMAutoPauseMusic* autoPauseMusic;
+ BGMAppVolumes* appVolumes;
+ BGMAudioDeviceManager* audioDevices;
+ BGMPreferencesMenu* prefsMenu;
+}
+
+- (void) awakeFromNib {
+ // Set up the status bar item
+ statusBarItem = [[NSStatusBar systemStatusBar] statusItemWithLength:NSSquareStatusItemLength];
+
+ // Set the icon
+ NSImage* icon = [NSImage imageNamed:@"FermataIcon"];
+ if (icon != nil) {
+ CGFloat lengthMinusPadding = [[statusBarItem button] frame].size.height * (1 - kStatusBarIconPadding);
+ [icon setSize:NSMakeSize(lengthMinusPadding, lengthMinusPadding)];
+ // Make the icon a "template image" so it gets drawn colour-inverted when it's highlighted or the status
+ // bar's in dark mode
+ [icon setTemplate:YES];
+ statusBarItem.button.image = icon;
+ } else {
+ // If our icon is missing for some reason, fallback to a fermata character (1D110)
+ statusBarItem.button.title = @"𝄐";
+ }
+
+ // Set the main menu
+ statusBarItem.menu = self.bgmMenu;
+}
+
+- (void) applicationDidFinishLaunching:(NSNotification*)aNotification {
+ #pragma unused (aNotification)
+
+ // Coordinates the audio devices (BGMDevice and the output device): manages playthrough, volume/mute controls, etc.
+ NSError* err;
+ audioDevices = [[BGMAudioDeviceManager alloc] initWithError:&err];
+ if (audioDevices == nil) {
+ [self showDeviceNotFoundErrorMessageAndExit:err.code];
+ }
+ [audioDevices setBGMDeviceAsOSDefault];
+
+ // Register the preference defaults. These are the preferences/state that only apply to BGMApp. The others are
+ // persisted on BGMDriver.
+ NSDictionary* appDefaults = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES]
+ forKey:@"AutoPauseMusicEnabled"];
+ [[NSUserDefaults standardUserDefaults] registerDefaults:appDefaults];
+
+ autoPauseMusic = [[BGMAutoPauseMusic alloc] initWithAudioDevices:audioDevices];
+
+ // Enable auto-pausing music if it's enabled in the user's preferences (which it is by default)
+ if ([[NSUserDefaults standardUserDefaults] boolForKey:@"AutoPauseMusicEnabled"]) {
+ [self toggleAutoPauseMusic:self];
+ }
+
+ appVolumes = [[BGMAppVolumes alloc] initWithMenu:[self bgmMenu]
+ appVolumeView:[self appVolumeView]
+ audioDevices:audioDevices];
+
+ prefsMenu = [[BGMPreferencesMenu alloc] initWithbgmMenu:[self bgmMenu]
+ audioDevices:audioDevices
+ aboutPanel:[self aboutPanel]
+ aboutPanelLicenseView:[self aboutPanelLicenseView]];
+}
+
+- (void) showDeviceNotFoundErrorMessageAndExit:(NSInteger)code {
+ // Show an error dialog and exit if either BGMDevice wasn't found on the system or we couldn't find any output devices
+
+ NSAlert* alert = [NSAlert new];
+
+ if (code == kBGMErrorCode_BGMDeviceNotFound) {
+ // TODO: Check whether the driver files are in /Library/Audio/Plug-Ins/HAL and offer to install them if not. Also,
+ // it would be nice if we could restart coreaudiod automatically (using launchd).
+ [alert setMessageText:@"Could not find the Background Music virtual audio device."];
+ [alert setInformativeText:@"Make sure you've installed Background Music.driver to /Library/Audio/Plug-Ins/HAL and restarted coreaudiod (e.g. \"sudo killall coreaudiod\")."];
+ } else if(code == kBGMErrorCode_OutputDeviceNotFound) {
+ [alert setMessageText:@"Could not find an audio output device."];
+ [alert setInformativeText:@"If you do have one installed, this is probably a bug. Sorry about that. Feel free to file an issue on GitHub."];
+ }
+
+ [alert runModal];
+ [NSApp terminate:self];
+}
+
+- (void) applicationWillTerminate:(NSNotification*)aNotification {
+ #pragma unused (aNotification)
+ [audioDevices unsetBGMDeviceAsOSDefault];
+}
+
+- (IBAction) toggleAutoPauseMusic:(id)sender {
+ #pragma unused (sender)
+
+ if (self.autoPauseMenuItem.state == NSOnState) {
+ self.autoPauseMenuItem.state = NSOffState;
+ [autoPauseMusic disable];
+ } else {
+ self.autoPauseMenuItem.state = NSOnState;
+ [autoPauseMusic enable];
+ }
+
+ // Persist the change in the user's preferences
+ [[NSUserDefaults standardUserDefaults] setBool:(self.autoPauseMenuItem.state == NSOnState)
+ forKey:@"AutoPauseMusicEnabled"];
+}
+
+@end
+
@@ -0,0 +1,57 @@
+// This file is part of Background Music.
+//
+// Background Music is free software: you can redistribute it and/or
+// modify it under the terms of the GNU General Public License as
+// published by the Free Software Foundation, either version 2 of the
+// License, or (at your option) any later version.
+//
+// Background Music is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Background Music. If not, see <http://www.gnu.org/licenses/>.
+
+//
+// BGMAppVolumes.h
+// BGMApp
+//
+// Copyright © 2016 Kyle Neideck
+//
+
+// Local Includes
+#import "BGMAudioDeviceManager.h"
+
+// System Includes
+#import <Cocoa/Cocoa.h>
+
+
+@interface BGMAppVolumes : NSObject
+
+- (id) initWithMenu:(NSMenu*)menu appVolumeView:(NSView*)view audioDevices:(BGMAudioDeviceManager*)audioDevices;
+
+@end
+
+// Protocol for the UI custom classes
+
+@protocol BGMAppVolumeSubview <NSObject>
+
+- (void) setUpWithApp:(NSRunningApplication*)app context:(BGMAppVolumes*)ctx;
+
+@end
+
+// Custom classes for the UI elements in the app volume menu items
+
+@interface BGMAVM_AppIcon : NSImageView <BGMAppVolumeSubview>
+@end
+
+@interface BGMAVM_AppNameLabel : NSTextField <BGMAppVolumeSubview>
+@end
+
+@interface BGMAVM_VolumeSlider : NSSlider <BGMAppVolumeSubview>
+
+- (void) setRelativeVolume:(NSNumber*)relativeVolume;
+
+@end
+
Oops, something went wrong.

0 comments on commit b17d736

Please sign in to comment.