├── .gitignore ├── CREDITS.md ├── DrumMachine.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist └── xcuserdata │ └── vadmarko.xcuserdatad │ └── xcschemes │ └── xcschememanagement.plist ├── DrumMachine ├── DrumMachine.xcdatamodeld │ ├── .xccurrentversion │ └── DrumMachine.xcdatamodel │ │ └── contents ├── DrumMachine │ └── DrumsTriggerView.swift ├── Resources │ ├── Assets.xcassets │ │ ├── AppIcon.appiconset │ │ │ └── Contents.json │ │ └── Contents.json │ ├── Base.lproj │ │ ├── LaunchScreen.storyboard │ │ └── Main.storyboard │ ├── DrumSounds │ │ ├── hi-hats.wav │ │ ├── kick.wav │ │ ├── pusefinn.wav │ │ └── snare.wav │ └── Info.plist └── Sources │ ├── AppDelegate.swift │ ├── Extensions │ └── UIColor+Extensions.swift │ ├── Features │ ├── Drums │ │ ├── DrumsFooterView.swift │ │ └── DrumsViewController.swift │ ├── Instruments │ │ ├── Instrument.swift │ │ └── InstrumentSelectorViewController.swift │ └── Pad │ │ ├── DrumPadCollectionViewCell.swift │ │ ├── DrumPadPlayer.swift │ │ └── DrumPadViewController.swift │ └── ViewController.swift ├── GitHub └── image.jpg └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | # OS X 2 | .DS_Store 3 | .AppleDouble 4 | .LSOverride 5 | Icon 6 | ._* 7 | .Spotlight-V100 8 | .Trashes 9 | 10 | # Xcode 11 | # 12 | build/ 13 | *.pbxuser 14 | !default.pbxuser 15 | *.mode1v3 16 | !default.mode1v3 17 | *.mode2v3 18 | !default.mode2v3 19 | *.perspectivev3 20 | !default.perspectivev3 21 | xcuserdata 22 | *.xccheckout 23 | *.moved-aside 24 | DerivedData 25 | *.hmap 26 | *.ipa 27 | *.xcuserstate 28 | .idea/ 29 | 30 | # CocoaPods 31 | Pods 32 | 33 | # Carthage 34 | Carthage 35 | 36 | # SPM 37 | .build/ 38 | -------------------------------------------------------------------------------- /CREDITS.md: -------------------------------------------------------------------------------- 1 | # Credits 2 | 3 | **Sounds used in the app:** 4 | 5 | * Kick: https://freesound.org/people/DWSD/sounds/171104/ 6 | * Snare: https://freesound.org/people/alexthegr81/sounds/212208/ 7 | * Hi-Hats: https://freesound.org/people/soneproject/sounds/271402/ 8 | * Cat: https://freesound.org/people/timtube/sounds/61259/ 9 | -------------------------------------------------------------------------------- /DrumMachine.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 50; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | CF139923214A6EC80035D626 /* UIColor+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF139922214A6EC80035D626 /* UIColor+Extensions.swift */; }; 11 | CF139925214BA34D0035D626 /* DrumPadPlayer.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF139924214BA34D0035D626 /* DrumPadPlayer.swift */; }; 12 | CF7F46F021414231004DB629 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF7F46EF21414231004DB629 /* AppDelegate.swift */; }; 13 | CF7F46F221414231004DB629 /* ViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF7F46F121414231004DB629 /* ViewController.swift */; }; 14 | CF7F46F521414231004DB629 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CF7F46F321414231004DB629 /* Main.storyboard */; }; 15 | CF7F46FA21414232004DB629 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = CF7F46F921414232004DB629 /* Assets.xcassets */; }; 16 | CF7F46FD21414232004DB629 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = CF7F46FB21414232004DB629 /* LaunchScreen.storyboard */; }; 17 | CF7F470D21414286004DB629 /* DrumPadCollectionViewCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF7F470721414286004DB629 /* DrumPadCollectionViewCell.swift */; }; 18 | CF7F470E21414286004DB629 /* Instrument.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF7F470821414286004DB629 /* Instrument.swift */; }; 19 | CF7F470F21414286004DB629 /* InstrumentSelectorViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF7F470921414286004DB629 /* InstrumentSelectorViewController.swift */; }; 20 | CF7F471021414286004DB629 /* DrumPadViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF7F470B21414286004DB629 /* DrumPadViewController.swift */; }; 21 | CF7F471121414286004DB629 /* DrumsViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF7F470C21414286004DB629 /* DrumsViewController.swift */; }; 22 | CF7F471721415E2D004DB629 /* kick.wav in Resources */ = {isa = PBXBuildFile; fileRef = CF7F471521415E2D004DB629 /* kick.wav */; }; 23 | CF7F471821415E2D004DB629 /* snare.wav in Resources */ = {isa = PBXBuildFile; fileRef = CF7F471621415E2D004DB629 /* snare.wav */; }; 24 | CF7F471A21416E16004DB629 /* pusefinn.wav in Resources */ = {isa = PBXBuildFile; fileRef = CF7F471921416E16004DB629 /* pusefinn.wav */; }; 25 | CF7F471C21416E29004DB629 /* hi-hats.wav in Resources */ = {isa = PBXBuildFile; fileRef = CF7F471B21416E29004DB629 /* hi-hats.wav */; }; 26 | CF7F471E21417DF3004DB629 /* DrumsFooterView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CF7F471D21417DF3004DB629 /* DrumsFooterView.swift */; }; 27 | /* End PBXBuildFile section */ 28 | 29 | /* Begin PBXFileReference section */ 30 | CF139922214A6EC80035D626 /* UIColor+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIColor+Extensions.swift"; sourceTree = ""; }; 31 | CF139924214BA34D0035D626 /* DrumPadPlayer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DrumPadPlayer.swift; sourceTree = ""; }; 32 | CF7F46EC21414231004DB629 /* DrumMachine.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = DrumMachine.app; sourceTree = BUILT_PRODUCTS_DIR; }; 33 | CF7F46EF21414231004DB629 /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 34 | CF7F46F121414231004DB629 /* ViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 35 | CF7F46F421414231004DB629 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 36 | CF7F46F921414232004DB629 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 37 | CF7F46FC21414232004DB629 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = ""; }; 38 | CF7F46FE21414232004DB629 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 39 | CF7F470721414286004DB629 /* DrumPadCollectionViewCell.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DrumPadCollectionViewCell.swift; sourceTree = ""; }; 40 | CF7F470821414286004DB629 /* Instrument.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Instrument.swift; sourceTree = ""; }; 41 | CF7F470921414286004DB629 /* InstrumentSelectorViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = InstrumentSelectorViewController.swift; sourceTree = ""; }; 42 | CF7F470B21414286004DB629 /* DrumPadViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DrumPadViewController.swift; sourceTree = ""; }; 43 | CF7F470C21414286004DB629 /* DrumsViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DrumsViewController.swift; sourceTree = ""; }; 44 | CF7F471521415E2D004DB629 /* kick.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = kick.wav; sourceTree = ""; }; 45 | CF7F471621415E2D004DB629 /* snare.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = snare.wav; sourceTree = ""; }; 46 | CF7F471921416E16004DB629 /* pusefinn.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = pusefinn.wav; sourceTree = ""; }; 47 | CF7F471B21416E29004DB629 /* hi-hats.wav */ = {isa = PBXFileReference; lastKnownFileType = audio.wav; path = "hi-hats.wav"; sourceTree = ""; }; 48 | CF7F471D21417DF3004DB629 /* DrumsFooterView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DrumsFooterView.swift; sourceTree = ""; }; 49 | /* End PBXFileReference section */ 50 | 51 | /* Begin PBXFrameworksBuildPhase section */ 52 | CF7F46E921414231004DB629 /* Frameworks */ = { 53 | isa = PBXFrameworksBuildPhase; 54 | buildActionMask = 2147483647; 55 | files = ( 56 | ); 57 | runOnlyForDeploymentPostprocessing = 0; 58 | }; 59 | /* End PBXFrameworksBuildPhase section */ 60 | 61 | /* Begin PBXGroup section */ 62 | CF139921214A6EBC0035D626 /* Extensions */ = { 63 | isa = PBXGroup; 64 | children = ( 65 | CF139922214A6EC80035D626 /* UIColor+Extensions.swift */, 66 | ); 67 | path = Extensions; 68 | sourceTree = ""; 69 | }; 70 | CF139926214BA3880035D626 /* Resources */ = { 71 | isa = PBXGroup; 72 | children = ( 73 | CF7F4720214182BD004DB629 /* DrumSounds */, 74 | CF7F46F321414231004DB629 /* Main.storyboard */, 75 | CF7F46F921414232004DB629 /* Assets.xcassets */, 76 | CF7F46FB21414232004DB629 /* LaunchScreen.storyboard */, 77 | CF7F46FE21414232004DB629 /* Info.plist */, 78 | ); 79 | path = Resources; 80 | sourceTree = ""; 81 | }; 82 | CF139927214BA38F0035D626 /* Sources */ = { 83 | isa = PBXGroup; 84 | children = ( 85 | CF7F46EF21414231004DB629 /* AppDelegate.swift */, 86 | CF7F46F121414231004DB629 /* ViewController.swift */, 87 | CF139921214A6EBC0035D626 /* Extensions */, 88 | CF7F471221414320004DB629 /* Features */, 89 | ); 90 | path = Sources; 91 | sourceTree = ""; 92 | }; 93 | CF7F46E321414231004DB629 = { 94 | isa = PBXGroup; 95 | children = ( 96 | CF7F46EE21414231004DB629 /* DrumMachine */, 97 | CF7F46ED21414231004DB629 /* Products */, 98 | ); 99 | sourceTree = ""; 100 | }; 101 | CF7F46ED21414231004DB629 /* Products */ = { 102 | isa = PBXGroup; 103 | children = ( 104 | CF7F46EC21414231004DB629 /* DrumMachine.app */, 105 | ); 106 | name = Products; 107 | sourceTree = ""; 108 | }; 109 | CF7F46EE21414231004DB629 /* DrumMachine */ = { 110 | isa = PBXGroup; 111 | children = ( 112 | CF139927214BA38F0035D626 /* Sources */, 113 | CF139926214BA3880035D626 /* Resources */, 114 | ); 115 | path = DrumMachine; 116 | sourceTree = ""; 117 | }; 118 | CF7F470621414286004DB629 /* Instruments */ = { 119 | isa = PBXGroup; 120 | children = ( 121 | CF7F470821414286004DB629 /* Instrument.swift */, 122 | CF7F470921414286004DB629 /* InstrumentSelectorViewController.swift */, 123 | ); 124 | path = Instruments; 125 | sourceTree = ""; 126 | }; 127 | CF7F470A21414286004DB629 /* Pad */ = { 128 | isa = PBXGroup; 129 | children = ( 130 | CF7F470721414286004DB629 /* DrumPadCollectionViewCell.swift */, 131 | CF139924214BA34D0035D626 /* DrumPadPlayer.swift */, 132 | CF7F470B21414286004DB629 /* DrumPadViewController.swift */, 133 | ); 134 | path = Pad; 135 | sourceTree = ""; 136 | }; 137 | CF7F471221414320004DB629 /* Features */ = { 138 | isa = PBXGroup; 139 | children = ( 140 | CF7F471F214182AB004DB629 /* Drums */, 141 | CF7F470621414286004DB629 /* Instruments */, 142 | CF7F470A21414286004DB629 /* Pad */, 143 | ); 144 | path = Features; 145 | sourceTree = ""; 146 | }; 147 | CF7F471F214182AB004DB629 /* Drums */ = { 148 | isa = PBXGroup; 149 | children = ( 150 | CF7F471D21417DF3004DB629 /* DrumsFooterView.swift */, 151 | CF7F470C21414286004DB629 /* DrumsViewController.swift */, 152 | ); 153 | path = Drums; 154 | sourceTree = ""; 155 | }; 156 | CF7F4720214182BD004DB629 /* DrumSounds */ = { 157 | isa = PBXGroup; 158 | children = ( 159 | CF7F471521415E2D004DB629 /* kick.wav */, 160 | CF7F471B21416E29004DB629 /* hi-hats.wav */, 161 | CF7F471921416E16004DB629 /* pusefinn.wav */, 162 | CF7F471621415E2D004DB629 /* snare.wav */, 163 | ); 164 | path = DrumSounds; 165 | sourceTree = ""; 166 | }; 167 | /* End PBXGroup section */ 168 | 169 | /* Begin PBXNativeTarget section */ 170 | CF7F46EB21414231004DB629 /* DrumMachine */ = { 171 | isa = PBXNativeTarget; 172 | buildConfigurationList = CF7F470121414232004DB629 /* Build configuration list for PBXNativeTarget "DrumMachine" */; 173 | buildPhases = ( 174 | CF7F46E821414231004DB629 /* Sources */, 175 | CF7F46E921414231004DB629 /* Frameworks */, 176 | CF7F46EA21414231004DB629 /* Resources */, 177 | ); 178 | buildRules = ( 179 | ); 180 | dependencies = ( 181 | ); 182 | name = DrumMachine; 183 | productName = DrumMachine; 184 | productReference = CF7F46EC21414231004DB629 /* DrumMachine.app */; 185 | productType = "com.apple.product-type.application"; 186 | }; 187 | /* End PBXNativeTarget section */ 188 | 189 | /* Begin PBXProject section */ 190 | CF7F46E421414231004DB629 /* Project object */ = { 191 | isa = PBXProject; 192 | attributes = { 193 | LastSwiftUpdateCheck = 0940; 194 | LastUpgradeCheck = 0940; 195 | ORGANIZATIONNAME = "FINN.no AS"; 196 | TargetAttributes = { 197 | CF7F46EB21414231004DB629 = { 198 | CreatedOnToolsVersion = 9.4.1; 199 | }; 200 | }; 201 | }; 202 | buildConfigurationList = CF7F46E721414231004DB629 /* Build configuration list for PBXProject "DrumMachine" */; 203 | compatibilityVersion = "Xcode 9.3"; 204 | developmentRegion = en; 205 | hasScannedForEncodings = 0; 206 | knownRegions = ( 207 | en, 208 | Base, 209 | ); 210 | mainGroup = CF7F46E321414231004DB629; 211 | productRefGroup = CF7F46ED21414231004DB629 /* Products */; 212 | projectDirPath = ""; 213 | projectRoot = ""; 214 | targets = ( 215 | CF7F46EB21414231004DB629 /* DrumMachine */, 216 | ); 217 | }; 218 | /* End PBXProject section */ 219 | 220 | /* Begin PBXResourcesBuildPhase section */ 221 | CF7F46EA21414231004DB629 /* Resources */ = { 222 | isa = PBXResourcesBuildPhase; 223 | buildActionMask = 2147483647; 224 | files = ( 225 | CF7F46FD21414232004DB629 /* LaunchScreen.storyboard in Resources */, 226 | CF7F46FA21414232004DB629 /* Assets.xcassets in Resources */, 227 | CF7F471721415E2D004DB629 /* kick.wav in Resources */, 228 | CF7F471A21416E16004DB629 /* pusefinn.wav in Resources */, 229 | CF7F471C21416E29004DB629 /* hi-hats.wav in Resources */, 230 | CF7F471821415E2D004DB629 /* snare.wav in Resources */, 231 | CF7F46F521414231004DB629 /* Main.storyboard in Resources */, 232 | ); 233 | runOnlyForDeploymentPostprocessing = 0; 234 | }; 235 | /* End PBXResourcesBuildPhase section */ 236 | 237 | /* Begin PBXSourcesBuildPhase section */ 238 | CF7F46E821414231004DB629 /* Sources */ = { 239 | isa = PBXSourcesBuildPhase; 240 | buildActionMask = 2147483647; 241 | files = ( 242 | CF7F470F21414286004DB629 /* InstrumentSelectorViewController.swift in Sources */, 243 | CF139923214A6EC80035D626 /* UIColor+Extensions.swift in Sources */, 244 | CF7F471021414286004DB629 /* DrumPadViewController.swift in Sources */, 245 | CF7F471121414286004DB629 /* DrumsViewController.swift in Sources */, 246 | CF7F470E21414286004DB629 /* Instrument.swift in Sources */, 247 | CF7F46F221414231004DB629 /* ViewController.swift in Sources */, 248 | CF139925214BA34D0035D626 /* DrumPadPlayer.swift in Sources */, 249 | CF7F471E21417DF3004DB629 /* DrumsFooterView.swift in Sources */, 250 | CF7F470D21414286004DB629 /* DrumPadCollectionViewCell.swift in Sources */, 251 | CF7F46F021414231004DB629 /* AppDelegate.swift in Sources */, 252 | ); 253 | runOnlyForDeploymentPostprocessing = 0; 254 | }; 255 | /* End PBXSourcesBuildPhase section */ 256 | 257 | /* Begin PBXVariantGroup section */ 258 | CF7F46F321414231004DB629 /* Main.storyboard */ = { 259 | isa = PBXVariantGroup; 260 | children = ( 261 | CF7F46F421414231004DB629 /* Base */, 262 | ); 263 | name = Main.storyboard; 264 | sourceTree = ""; 265 | }; 266 | CF7F46FB21414232004DB629 /* LaunchScreen.storyboard */ = { 267 | isa = PBXVariantGroup; 268 | children = ( 269 | CF7F46FC21414232004DB629 /* Base */, 270 | ); 271 | name = LaunchScreen.storyboard; 272 | sourceTree = ""; 273 | }; 274 | /* End PBXVariantGroup section */ 275 | 276 | /* Begin XCBuildConfiguration section */ 277 | CF7F46FF21414232004DB629 /* Debug */ = { 278 | isa = XCBuildConfiguration; 279 | buildSettings = { 280 | ALWAYS_SEARCH_USER_PATHS = NO; 281 | CLANG_ANALYZER_NONNULL = YES; 282 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 283 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 284 | CLANG_CXX_LIBRARY = "libc++"; 285 | CLANG_ENABLE_MODULES = YES; 286 | CLANG_ENABLE_OBJC_ARC = YES; 287 | CLANG_ENABLE_OBJC_WEAK = YES; 288 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 289 | CLANG_WARN_BOOL_CONVERSION = YES; 290 | CLANG_WARN_COMMA = YES; 291 | CLANG_WARN_CONSTANT_CONVERSION = YES; 292 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 293 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 294 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 295 | CLANG_WARN_EMPTY_BODY = YES; 296 | CLANG_WARN_ENUM_CONVERSION = YES; 297 | CLANG_WARN_INFINITE_RECURSION = YES; 298 | CLANG_WARN_INT_CONVERSION = YES; 299 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 300 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 301 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 302 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 303 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 304 | CLANG_WARN_STRICT_PROTOTYPES = YES; 305 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 306 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 307 | CLANG_WARN_UNREACHABLE_CODE = YES; 308 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 309 | CODE_SIGN_IDENTITY = "iPhone Developer"; 310 | COPY_PHASE_STRIP = NO; 311 | DEBUG_INFORMATION_FORMAT = dwarf; 312 | ENABLE_STRICT_OBJC_MSGSEND = YES; 313 | ENABLE_TESTABILITY = YES; 314 | GCC_C_LANGUAGE_STANDARD = gnu11; 315 | GCC_DYNAMIC_NO_PIC = NO; 316 | GCC_NO_COMMON_BLOCKS = YES; 317 | GCC_OPTIMIZATION_LEVEL = 0; 318 | GCC_PREPROCESSOR_DEFINITIONS = ( 319 | "DEBUG=1", 320 | "$(inherited)", 321 | ); 322 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 323 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 324 | GCC_WARN_UNDECLARED_SELECTOR = YES; 325 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 326 | GCC_WARN_UNUSED_FUNCTION = YES; 327 | GCC_WARN_UNUSED_VARIABLE = YES; 328 | IPHONEOS_DEPLOYMENT_TARGET = 11.4; 329 | MTL_ENABLE_DEBUG_INFO = YES; 330 | ONLY_ACTIVE_ARCH = YES; 331 | SDKROOT = iphoneos; 332 | SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; 333 | SWIFT_OPTIMIZATION_LEVEL = "-Onone"; 334 | }; 335 | name = Debug; 336 | }; 337 | CF7F470021414232004DB629 /* Release */ = { 338 | isa = XCBuildConfiguration; 339 | buildSettings = { 340 | ALWAYS_SEARCH_USER_PATHS = NO; 341 | CLANG_ANALYZER_NONNULL = YES; 342 | CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; 343 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++14"; 344 | CLANG_CXX_LIBRARY = "libc++"; 345 | CLANG_ENABLE_MODULES = YES; 346 | CLANG_ENABLE_OBJC_ARC = YES; 347 | CLANG_ENABLE_OBJC_WEAK = YES; 348 | CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; 349 | CLANG_WARN_BOOL_CONVERSION = YES; 350 | CLANG_WARN_COMMA = YES; 351 | CLANG_WARN_CONSTANT_CONVERSION = YES; 352 | CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; 353 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 354 | CLANG_WARN_DOCUMENTATION_COMMENTS = YES; 355 | CLANG_WARN_EMPTY_BODY = YES; 356 | CLANG_WARN_ENUM_CONVERSION = YES; 357 | CLANG_WARN_INFINITE_RECURSION = YES; 358 | CLANG_WARN_INT_CONVERSION = YES; 359 | CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; 360 | CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; 361 | CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; 362 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 363 | CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; 364 | CLANG_WARN_STRICT_PROTOTYPES = YES; 365 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 366 | CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; 367 | CLANG_WARN_UNREACHABLE_CODE = YES; 368 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 369 | CODE_SIGN_IDENTITY = "iPhone Developer"; 370 | COPY_PHASE_STRIP = NO; 371 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 372 | ENABLE_NS_ASSERTIONS = NO; 373 | ENABLE_STRICT_OBJC_MSGSEND = YES; 374 | GCC_C_LANGUAGE_STANDARD = gnu11; 375 | GCC_NO_COMMON_BLOCKS = YES; 376 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 377 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 378 | GCC_WARN_UNDECLARED_SELECTOR = YES; 379 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 380 | GCC_WARN_UNUSED_FUNCTION = YES; 381 | GCC_WARN_UNUSED_VARIABLE = YES; 382 | IPHONEOS_DEPLOYMENT_TARGET = 11.4; 383 | MTL_ENABLE_DEBUG_INFO = NO; 384 | SDKROOT = iphoneos; 385 | SWIFT_COMPILATION_MODE = wholemodule; 386 | SWIFT_OPTIMIZATION_LEVEL = "-O"; 387 | VALIDATE_PRODUCT = YES; 388 | }; 389 | name = Release; 390 | }; 391 | CF7F470221414232004DB629 /* Debug */ = { 392 | isa = XCBuildConfiguration; 393 | buildSettings = { 394 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 395 | CODE_SIGN_STYLE = Automatic; 396 | INFOPLIST_FILE = "$(SRCROOT)/DrumMachine/Resources/Info.plist"; 397 | LD_RUNPATH_SEARCH_PATHS = ( 398 | "$(inherited)", 399 | "@executable_path/Frameworks", 400 | ); 401 | PRODUCT_BUNDLE_IDENTIFIER = no.finn.DrumMachine; 402 | PRODUCT_NAME = "$(TARGET_NAME)"; 403 | SWIFT_VERSION = 4.0; 404 | TARGETED_DEVICE_FAMILY = "1,2"; 405 | }; 406 | name = Debug; 407 | }; 408 | CF7F470321414232004DB629 /* Release */ = { 409 | isa = XCBuildConfiguration; 410 | buildSettings = { 411 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 412 | CODE_SIGN_STYLE = Automatic; 413 | INFOPLIST_FILE = "$(SRCROOT)/DrumMachine/Resources/Info.plist"; 414 | LD_RUNPATH_SEARCH_PATHS = ( 415 | "$(inherited)", 416 | "@executable_path/Frameworks", 417 | ); 418 | PRODUCT_BUNDLE_IDENTIFIER = no.finn.DrumMachine; 419 | PRODUCT_NAME = "$(TARGET_NAME)"; 420 | SWIFT_VERSION = 4.0; 421 | TARGETED_DEVICE_FAMILY = "1,2"; 422 | }; 423 | name = Release; 424 | }; 425 | /* End XCBuildConfiguration section */ 426 | 427 | /* Begin XCConfigurationList section */ 428 | CF7F46E721414231004DB629 /* Build configuration list for PBXProject "DrumMachine" */ = { 429 | isa = XCConfigurationList; 430 | buildConfigurations = ( 431 | CF7F46FF21414232004DB629 /* Debug */, 432 | CF7F470021414232004DB629 /* Release */, 433 | ); 434 | defaultConfigurationIsVisible = 0; 435 | defaultConfigurationName = Release; 436 | }; 437 | CF7F470121414232004DB629 /* Build configuration list for PBXNativeTarget "DrumMachine" */ = { 438 | isa = XCConfigurationList; 439 | buildConfigurations = ( 440 | CF7F470221414232004DB629 /* Debug */, 441 | CF7F470321414232004DB629 /* Release */, 442 | ); 443 | defaultConfigurationIsVisible = 0; 444 | defaultConfigurationName = Release; 445 | }; 446 | /* End XCConfigurationList section */ 447 | }; 448 | rootObject = CF7F46E421414231004DB629 /* Project object */; 449 | } 450 | -------------------------------------------------------------------------------- /DrumMachine.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /DrumMachine.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /DrumMachine.xcodeproj/xcuserdata/vadmarko.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | DrumMachine.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /DrumMachine/DrumMachine.xcdatamodeld/.xccurrentversion: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /DrumMachine/DrumMachine.xcdatamodeld/DrumMachine.xcdatamodel/contents: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /DrumMachine/DrumMachine/DrumsTriggerView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DrumsTriggerView.swift 3 | // FINN 4 | // 5 | // Created by Markov, Vadym on 06/09/2018. 6 | // Copyright © 2018 FINN.no. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | final class DrumsTriggerView: UIView { 12 | private(set) lazy var button: PrimaryButton = { 13 | let button = PrimaryButton() 14 | button.translatesAutoresizingMaskIntoConstraints = false 15 | button.setTitle("Play Drums", for: .normal) 16 | return button 17 | }() 18 | 19 | // MARK: - Init 20 | 21 | override init(frame: CGRect) { 22 | super.init(frame: frame) 23 | backgroundColor = .white 24 | addSubview(button) 25 | setupConstraints() 26 | } 27 | 28 | required init?(coder aDecoder: NSCoder) { 29 | fatalError("init(coder:) has not been implemented") 30 | } 31 | 32 | // MARK: - Layout 33 | 34 | private func setupConstraints() { 35 | NSLayoutConstraint.activate([ 36 | button.centerYAnchor.constraint(equalTo: centerYAnchor), 37 | button.centerXAnchor.constraint(equalTo: centerXAnchor), 38 | button.widthAnchor.constraint(equalTo: widthAnchor, multiplier: 0.7), 39 | button.heightAnchor.constraint(equalTo: heightAnchor, multiplier: 0.6) 40 | ]) 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /DrumMachine/Resources/Assets.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | }, 43 | { 44 | "idiom" : "ipad", 45 | "size" : "20x20", 46 | "scale" : "1x" 47 | }, 48 | { 49 | "idiom" : "ipad", 50 | "size" : "20x20", 51 | "scale" : "2x" 52 | }, 53 | { 54 | "idiom" : "ipad", 55 | "size" : "29x29", 56 | "scale" : "1x" 57 | }, 58 | { 59 | "idiom" : "ipad", 60 | "size" : "29x29", 61 | "scale" : "2x" 62 | }, 63 | { 64 | "idiom" : "ipad", 65 | "size" : "40x40", 66 | "scale" : "1x" 67 | }, 68 | { 69 | "idiom" : "ipad", 70 | "size" : "40x40", 71 | "scale" : "2x" 72 | }, 73 | { 74 | "idiom" : "ipad", 75 | "size" : "76x76", 76 | "scale" : "1x" 77 | }, 78 | { 79 | "idiom" : "ipad", 80 | "size" : "76x76", 81 | "scale" : "2x" 82 | }, 83 | { 84 | "idiom" : "ipad", 85 | "size" : "83.5x83.5", 86 | "scale" : "2x" 87 | }, 88 | { 89 | "idiom" : "ios-marketing", 90 | "size" : "1024x1024", 91 | "scale" : "1x" 92 | } 93 | ], 94 | "info" : { 95 | "version" : 1, 96 | "author" : "xcode" 97 | } 98 | } -------------------------------------------------------------------------------- /DrumMachine/Resources/Assets.xcassets/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "info" : { 3 | "version" : 1, 4 | "author" : "xcode" 5 | } 6 | } -------------------------------------------------------------------------------- /DrumMachine/Resources/Base.lproj/LaunchScreen.storyboard: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /DrumMachine/Resources/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /DrumMachine/Resources/DrumSounds/hi-hats.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/finn-labs/DrumMachine/1327d9e44d5fd7863b7859f2c6948dd543a552f5/DrumMachine/Resources/DrumSounds/hi-hats.wav -------------------------------------------------------------------------------- /DrumMachine/Resources/DrumSounds/kick.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/finn-labs/DrumMachine/1327d9e44d5fd7863b7859f2c6948dd543a552f5/DrumMachine/Resources/DrumSounds/kick.wav -------------------------------------------------------------------------------- /DrumMachine/Resources/DrumSounds/pusefinn.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/finn-labs/DrumMachine/1327d9e44d5fd7863b7859f2c6948dd543a552f5/DrumMachine/Resources/DrumSounds/pusefinn.wav -------------------------------------------------------------------------------- /DrumMachine/Resources/DrumSounds/snare.wav: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/finn-labs/DrumMachine/1327d9e44d5fd7863b7859f2c6948dd543a552f5/DrumMachine/Resources/DrumSounds/snare.wav -------------------------------------------------------------------------------- /DrumMachine/Resources/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | $(DEVELOPMENT_LANGUAGE) 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | APPL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleVersion 20 | 1 21 | LSRequiresIPhoneOS 22 | 23 | UILaunchStoryboardName 24 | LaunchScreen 25 | UIMainStoryboardFile 26 | Main 27 | UIRequiredDeviceCapabilities 28 | 29 | armv7 30 | 31 | UISupportedInterfaceOrientations 32 | 33 | UIInterfaceOrientationPortrait 34 | 35 | UISupportedInterfaceOrientations~ipad 36 | 37 | UIInterfaceOrientationPortrait 38 | UIInterfaceOrientationPortraitUpsideDown 39 | UIInterfaceOrientationLandscapeLeft 40 | UIInterfaceOrientationLandscapeRight 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /DrumMachine/Sources/AppDelegate.swift: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.swift 3 | // DrumMachine 4 | // 5 | // Created by Markov, Vadym on 06/09/2018. 6 | // Copyright © 2018 FINN.no AS. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import CoreData 11 | 12 | @UIApplicationMain 13 | final class AppDelegate: UIResponder, UIApplicationDelegate { 14 | var window: UIWindow? 15 | 16 | func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { 17 | return true 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /DrumMachine/Sources/Extensions/UIColor+Extensions.swift: -------------------------------------------------------------------------------- 1 | // 2 | // UIColor+Extensions.swift 3 | // DrumMachine 4 | // 5 | // Created by Markov, Vadym on 13/09/2018. 6 | // Copyright © 2018 FINN.no AS. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | extension UIColor { 12 | class var ice: UIColor { 13 | return UIColor(r: 241, g: 249, b: 255)! 14 | } 15 | 16 | class var milk: UIColor { 17 | return UIColor(r: 255, g: 255, b: 255)! 18 | } 19 | 20 | class var secondaryBlue: UIColor { 21 | return UIColor(r: 6, g: 190, b: 251)! 22 | } 23 | 24 | class var banana: UIColor { 25 | return .init(red: 235/255.0, green: 201/255.0, blue: 62/255.0, alpha: 1.0) 26 | } 27 | 28 | class var cherry: UIColor { 29 | return UIColor(r: 218, g: 36, b: 0)! 30 | } 31 | 32 | class var watermelon: UIColor { 33 | return UIColor(r: 255, g: 88, b: 68)! 34 | } 35 | 36 | class var pea: UIColor { 37 | return UIColor(r: 104, g: 226, b: 184)! 38 | } 39 | 40 | convenience init?(r: CGFloat, g: CGFloat, b: CGFloat, a: CGFloat = 1.0) { 41 | self.init(red: r / 255.0, green: g / 255.0, blue: b / 255.0, alpha: a) 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /DrumMachine/Sources/Features/Drums/DrumsFooterView.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DrumsFooterView.swift 3 | // DrumMachine 4 | // 5 | // Created by Markov, Vadym on 06/09/2018. 6 | // Copyright © 2018 FINN.no AS. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | final class DrumsFooterView: UIView { 12 | private(set) lazy var leftButton: UIButton = { 13 | let button = UIButton() 14 | button.translatesAutoresizingMaskIntoConstraints = false 15 | button.setTitleColor(.ice, for: .normal) 16 | return button 17 | }() 18 | 19 | private(set) lazy var rightButton: UIButton = { 20 | let button = UIButton() 21 | button.translatesAutoresizingMaskIntoConstraints = false 22 | button.setTitleColor(.cherry, for: .normal) 23 | return button 24 | }() 25 | 26 | // MARK: - Init 27 | 28 | override init(frame: CGRect) { 29 | super.init(frame: frame) 30 | addSubview(leftButton) 31 | addSubview(rightButton) 32 | setupConstraints() 33 | } 34 | 35 | required init?(coder aDecoder: NSCoder) { 36 | fatalError("init(coder:) has not been implemented") 37 | } 38 | 39 | // MARK: - Layout 40 | 41 | private func setupConstraints() { 42 | let padding: CGFloat = 16 43 | NSLayoutConstraint.activate([ 44 | leftButton.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -padding), 45 | leftButton.leadingAnchor.constraint(equalTo: leadingAnchor, constant: padding), 46 | leftButton.heightAnchor.constraint(equalTo: heightAnchor), 47 | leftButton.widthAnchor.constraint(equalTo: widthAnchor, multiplier: 0.2), 48 | 49 | rightButton.bottomAnchor.constraint(equalTo: bottomAnchor, constant: -padding), 50 | rightButton.trailingAnchor.constraint(equalTo: trailingAnchor, constant: -padding), 51 | rightButton.heightAnchor.constraint(equalTo: heightAnchor), 52 | rightButton.widthAnchor.constraint(equalTo: widthAnchor, multiplier: 0.2), 53 | ]) 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /DrumMachine/Sources/Features/Drums/DrumsViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DrumsViewController.swift 3 | // FINN 4 | // 5 | // Created by Markov, Vadym on 06/09/2018. 6 | // Copyright © 2018 FINN.no. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | protocol DrumsViewControllerDelegate: AnyObject { 12 | func drumsViewControllerDidTapClose(_ controller: DrumsViewController) 13 | } 14 | 15 | final class DrumsViewController: UIViewController { 16 | weak var delegate: DrumsViewControllerDelegate? 17 | private var instrument: Instrument = .kick 18 | 19 | private lazy var selectorViewController = InstrumentSelectorViewController(instrument: self.instrument) 20 | private lazy var padViewController = DrumPadViewController(instrument: self.instrument) 21 | private lazy var footerView: DrumsFooterView = { 22 | let view = DrumsFooterView() 23 | view.translatesAutoresizingMaskIntoConstraints = false 24 | view.leftButton.setTitle("Reset", for: .normal) 25 | view.rightButton.setTitle("Close", for: .normal) 26 | return view 27 | }() 28 | 29 | // MARK: - Lifecycle 30 | 31 | override func viewDidLoad() { 32 | super.viewDidLoad() 33 | view.backgroundColor = .black 34 | 35 | add(childController: selectorViewController) 36 | add(childController: padViewController) 37 | view.addSubview(footerView) 38 | setupConstraints() 39 | 40 | selectorViewController.delegate = self 41 | footerView.leftButton.addTarget(self, action: #selector(resetButtonTapped(_:)), for: .touchUpInside) 42 | footerView.rightButton.addTarget(self, action: #selector(closeButtonTapped(_:)), for: .touchUpInside) 43 | } 44 | 45 | // MARK: - Layout 46 | 47 | private func setupConstraints() { 48 | let selectorView = selectorViewController.view! 49 | let padView = padViewController.view! 50 | 51 | selectorView.translatesAutoresizingMaskIntoConstraints = false 52 | padView.translatesAutoresizingMaskIntoConstraints = false 53 | 54 | if #available(iOS 11.0, *) { 55 | selectorView.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor).isActive = true 56 | } else { 57 | selectorView.topAnchor.constraint(equalTo: view.topAnchor).isActive = true 58 | } 59 | 60 | NSLayoutConstraint.activate([ 61 | selectorView.leadingAnchor.constraint(equalTo: view.leadingAnchor), 62 | selectorView.trailingAnchor.constraint(equalTo: view.trailingAnchor), 63 | selectorView.heightAnchor.constraint(equalToConstant: 100), 64 | 65 | padView.topAnchor.constraint(equalTo: selectorView.bottomAnchor, constant: 30), 66 | padView.leadingAnchor.constraint(equalTo: view.leadingAnchor), 67 | padView.trailingAnchor.constraint(equalTo: view.trailingAnchor), 68 | padView.bottomAnchor.constraint(equalTo: footerView.topAnchor), 69 | 70 | footerView.leadingAnchor.constraint(equalTo: view.leadingAnchor), 71 | footerView.trailingAnchor.constraint(equalTo: view.trailingAnchor) 72 | ]) 73 | 74 | if #available(iOS 11.0, *) { 75 | footerView.bottomAnchor.constraint(equalTo: view.safeAreaLayoutGuide.bottomAnchor).isActive = true 76 | } else { 77 | footerView.bottomAnchor.constraint(equalTo: view.bottomAnchor).isActive = true 78 | } 79 | } 80 | 81 | // MARK: - Actions 82 | 83 | @objc private func resetButtonTapped(_ sender: UIButton) { 84 | padViewController.reset() 85 | } 86 | 87 | @objc private func closeButtonTapped(_ sender: UIButton) { 88 | delegate?.drumsViewControllerDidTapClose(self) 89 | } 90 | } 91 | 92 | // MARK: - InstrumentSelectorViewControllerDelegate 93 | 94 | extension DrumsViewController: InstrumentSelectorViewControllerDelegate { 95 | func instrumentSelectorViewController(_ viewController: InstrumentSelectorViewController, 96 | didSelectInstrument instrument: Instrument) { 97 | self.instrument = instrument 98 | padViewController.instrument = instrument 99 | } 100 | } 101 | 102 | // MARK: - Private extensions 103 | 104 | private extension UIViewController { 105 | func add(childController: UIViewController) { 106 | childController.willMove(toParentViewController: self) 107 | addChildViewController(childController) 108 | view.addSubview(childController.view) 109 | childController.didMove(toParentViewController: self) 110 | } 111 | } 112 | -------------------------------------------------------------------------------- /DrumMachine/Sources/Features/Instruments/Instrument.swift: -------------------------------------------------------------------------------- 1 | // 2 | // Instrument.swift 3 | // FINN 4 | // 5 | // Created by Markov, Vadym on 06/09/2018. 6 | // Copyright © 2018 FINN.no. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | import AudioToolbox 11 | 12 | enum Instrument: String { 13 | case kick = "Kick" 14 | case snare = "Snare" 15 | case hats = "Hi-Hats" 16 | case cat = "PuseFINN" 17 | 18 | var color: UIColor { 19 | switch self { 20 | case .kick: 21 | return .pea 22 | case .snare: 23 | return .banana 24 | case .hats: 25 | return .watermelon 26 | case .cat: 27 | return .secondaryBlue 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /DrumMachine/Sources/Features/Instruments/InstrumentSelectorViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // InstrumentSelectorViewController.swift 3 | // FINN 4 | // 5 | // Created by Markov, Vadym on 06/09/2018. 6 | // Copyright © 2018 FINN.no. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | protocol InstrumentSelectorViewControllerDelegate: AnyObject { 12 | func instrumentSelectorViewController( 13 | _ viewController: InstrumentSelectorViewController, 14 | didSelectInstrument instrument: Instrument 15 | ) 16 | } 17 | 18 | final class InstrumentSelectorViewController: UIViewController { 19 | weak var delegate: InstrumentSelectorViewControllerDelegate? 20 | private var selectedInstrument: Instrument 21 | private var instruments: [Instrument] = [.kick, .snare, .hats, .cat] 22 | 23 | private lazy var titleLabel: UILabel = { 24 | let label = UILabel() 25 | label.font = UIFont.boldSystemFont(ofSize: 18) 26 | label.translatesAutoresizingMaskIntoConstraints = false 27 | label.textColor = .milk 28 | return label 29 | }() 30 | 31 | private lazy var segmentedControl: UISegmentedControl = { 32 | let segmentedControl = UISegmentedControl(items: self.instruments.map({ $0.rawValue })) 33 | segmentedControl.translatesAutoresizingMaskIntoConstraints = false 34 | segmentedControl.tintColor = .white 35 | return segmentedControl 36 | }() 37 | 38 | // MARK: - Init 39 | 40 | init(instrument: Instrument) { 41 | self.selectedInstrument = instrument 42 | super.init(nibName: nil, bundle: nil) 43 | } 44 | 45 | required init?(coder aDecoder: NSCoder) { 46 | fatalError("init(coder:) has not been implemented") 47 | } 48 | 49 | // MARK: - Lifecycle 50 | 51 | override func viewDidLoad() { 52 | super.viewDidLoad() 53 | view.backgroundColor = .black 54 | view.addSubview(titleLabel) 55 | view.addSubview(segmentedControl) 56 | setupConstraints() 57 | 58 | titleLabel.text = "Instruments" 59 | segmentedControl.selectedSegmentIndex = instruments.index(where: { $0 == selectedInstrument}) ?? 0 60 | segmentedControl.addTarget(self, action: #selector(handleSegmentedControlChange(_:)), for: .valueChanged) 61 | } 62 | 63 | // MARK: - Layout 64 | 65 | private func setupConstraints() { 66 | let spacing: CGFloat = 16 67 | 68 | NSLayoutConstraint.activate([ 69 | titleLabel.topAnchor.constraint(equalTo: view.topAnchor, constant: spacing), 70 | titleLabel.centerXAnchor.constraint(equalTo: view.centerXAnchor), 71 | 72 | segmentedControl.topAnchor.constraint(equalTo: titleLabel.bottomAnchor, constant: spacing), 73 | segmentedControl.leadingAnchor.constraint(equalTo: view.leadingAnchor, constant: spacing), 74 | segmentedControl.trailingAnchor.constraint(equalTo: view.trailingAnchor, constant: -spacing), 75 | segmentedControl.heightAnchor.constraint(equalTo: view.heightAnchor, multiplier: 0.4) 76 | ]) 77 | } 78 | 79 | // MARK: - Actions 80 | 81 | @objc private func handleSegmentedControlChange(_ sender: UISegmentedControl) { 82 | selectedInstrument = instruments[sender.selectedSegmentIndex] 83 | delegate?.instrumentSelectorViewController(self, didSelectInstrument: selectedInstrument) 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /DrumMachine/Sources/Features/Pad/DrumPadCollectionViewCell.swift: -------------------------------------------------------------------------------- 1 | // 2 | // InstrumentCollectionViewCell.swift 3 | // FINN 4 | // 5 | // Created by Markov, Vadym on 06/09/2018. 6 | // Copyright © 2018 FINN.no. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | final class DrumPadCollectionViewCell: UICollectionViewCell { 12 | private lazy var overlayLayer: CALayer = { 13 | let layer = CALayer() 14 | layer.backgroundColor = UIColor.init(white: 1, alpha: 0.8).cgColor 15 | return layer 16 | }() 17 | 18 | // MARK: - Init 19 | 20 | override init(frame: CGRect) { 21 | super.init(frame: frame) 22 | contentView.addInnerShadow(shadowColor: UIColor.red, shadowSize: 10, shadowOpacity: 0.1) 23 | contentView.layer.addSublayer(overlayLayer) 24 | setupStyles() 25 | } 26 | 27 | required init?(coder aDecoder: NSCoder) { 28 | fatalError("init(coder:) has not been implemented") 29 | } 30 | 31 | // MARK: - Layout 32 | 33 | override func layoutSubviews() { 34 | super.layoutSubviews() 35 | overlayLayer.frame = contentView.bounds 36 | overlayLayer.cornerRadius = contentView.layer.cornerRadius 37 | } 38 | 39 | // MARK: - Styles 40 | 41 | func flash(withDuration duration: TimeInterval) { 42 | let animation = CABasicAnimation(keyPath: "opacity") 43 | animation.fromValue = 1 44 | animation.toValue = 0.5 45 | animation.duration = duration 46 | animation.autoreverses = true 47 | animation.repeatCount = 1 48 | animation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionEaseInEaseOut) 49 | contentView.layer.add(animation, forKey: nil) 50 | } 51 | 52 | func updateOverlayVisibility(isVisible: Bool) { 53 | overlayLayer.isHidden = !isVisible 54 | } 55 | 56 | private func setupStyles() { 57 | contentView.layer.masksToBounds = true 58 | contentView.layer.cornerRadius = 2 59 | 60 | contentView.layer.borderColor = UIColor.white.cgColor 61 | updateOverlayVisibility(isVisible: false) 62 | } 63 | } 64 | 65 | // MARK: - Private extensions 66 | 67 | private extension UIView { 68 | func addInnerShadow(shadowColor: UIColor, shadowSize: CGFloat, shadowOpacity: Float){ 69 | let shadowLayer = CAShapeLayer() 70 | shadowLayer.frame = bounds 71 | shadowLayer.shadowColor = shadowColor.cgColor 72 | shadowLayer.shadowOffset = CGSize(width: 0.0, height: 0.0) 73 | shadowLayer.shadowOpacity = shadowOpacity 74 | shadowLayer.shadowRadius = shadowSize 75 | shadowLayer.fillRule = kCAFillRuleEvenOdd 76 | 77 | let shadowPath = CGMutablePath() 78 | let insetRect = bounds.insetBy(dx: -shadowSize * 2.0, dy: -shadowSize * 2.0) 79 | let innerFrame = CGRect(x: 0.0, y: 0.0, width: frame.size.width, height: frame.size.height) 80 | 81 | shadowPath.addRect(insetRect) 82 | shadowPath.addRect(innerFrame) 83 | 84 | shadowLayer.path = shadowPath 85 | layer.addSublayer(shadowLayer) 86 | clipsToBounds = true 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /DrumMachine/Sources/Features/Pad/DrumPadPlayer.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DrumPadPlayer.swift 3 | // FINN 4 | // 5 | // Created by Markov, Vadym on 06/09/2018. 6 | // Copyright © 2018 FINN.no. All rights reserved. 7 | // 8 | 9 | import AVFoundation 10 | 11 | final class DrumPadPlayer { 12 | private let audioSession: AVAudioSession 13 | private let bundle: Bundle 14 | 15 | // MARK: - Init 16 | 17 | init(bundle: Bundle = .main, audioSession: AVAudioSession = .sharedInstance()) { 18 | self.bundle = bundle 19 | self.audioSession = audioSession 20 | try? audioSession.setCategory(AVAudioSessionCategoryPlayback) 21 | try? audioSession.setActive(true) 22 | } 23 | 24 | // MARK: - Player 25 | 26 | func play(instrument: Instrument) { 27 | guard let sound = makeSound(for: instrument) else { 28 | return 29 | } 30 | AudioServicesPlaySystemSound(sound) 31 | } 32 | 33 | private func makeSound(for instrument: Instrument) -> SystemSoundID? { 34 | let resource = instrument.rawValue.lowercased() 35 | 36 | guard let soundURL = Bundle.main.url(forResource: resource, withExtension: "wav") else { 37 | return nil 38 | } 39 | 40 | var sound: SystemSoundID = 0 41 | AudioServicesCreateSystemSoundID(soundURL as CFURL, &sound) 42 | return sound 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /DrumMachine/Sources/Features/Pad/DrumPadViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // DrumPadViewController.swift 3 | // FINN 4 | // 5 | // Created by Markov, Vadym on 06/09/2018. 6 | // Copyright © 2018 FINN.no. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | final class DrumPadViewController: UIViewController { 12 | private let padSpacing: CGFloat = 16 13 | private let cellSpacing: CGFloat = 4 14 | private let numberOfPads = 16 15 | private var currentPad = 0 16 | private var timer: Timer? 17 | private var beatsPerMinute: Float = 120 18 | 19 | private lazy var player = DrumPadPlayer() 20 | private lazy var compositions: [Instrument: [Bool]] = self.makeEmptyCompositions() 21 | 22 | var instrument: Instrument { 23 | didSet { 24 | collectionView.reloadData() 25 | } 26 | } 27 | 28 | private var timeInterval: Double { 29 | return (60.0 / Double(beatsPerMinute)) / 4 30 | } 31 | 32 | private lazy var collectionView: UICollectionView = makeCollectionView() 33 | private lazy var bpmSlider: UISlider = { 34 | let slider = UISlider() 35 | slider.minimumValue = 80 36 | slider.maximumValue = 160 37 | slider.tintColor = .pea 38 | slider.translatesAutoresizingMaskIntoConstraints = false 39 | return slider 40 | }() 41 | 42 | // MARK: - Init 43 | 44 | init(instrument: Instrument) { 45 | self.instrument = instrument 46 | super.init(nibName: nil, bundle: nil) 47 | } 48 | 49 | required init?(coder aDecoder: NSCoder) { 50 | fatalError("init(coder:) has not been implemented") 51 | } 52 | 53 | // MARK: - Lifecycle 54 | 55 | override func viewDidLoad() { 56 | super.viewDidLoad() 57 | view.backgroundColor = .black 58 | view.addSubview(collectionView) 59 | view.addSubview(bpmSlider) 60 | setupConstraints() 61 | 62 | bpmSlider.setValue(beatsPerMinute, animated: false) 63 | bpmSlider.addTarget(self, action: #selector(sliderValueChanged(_:)), for: .valueChanged) 64 | collectionView.reloadData() 65 | } 66 | 67 | override func viewDidAppear(_ animated: Bool) { 68 | super.viewDidAppear(animated) 69 | startLoop() 70 | } 71 | 72 | override func viewWillDisappear(_ animated: Bool) { 73 | super.viewWillDisappear(animated) 74 | endLoop() 75 | } 76 | 77 | // MARK: - Composition 78 | 79 | func reset() { 80 | endLoop() 81 | currentPad = 0 82 | compositions = makeEmptyCompositions() 83 | collectionView.reloadData() 84 | startLoop() 85 | } 86 | 87 | private func makeEmptyCompositions() -> [Instrument: [Bool]] { 88 | return [ 89 | .kick: Array(repeating: false, count: self.numberOfPads), 90 | .snare: Array(repeating: false, count: self.numberOfPads), 91 | .hats: Array(repeating: false, count: self.numberOfPads), 92 | .cat: Array(repeating: false, count: self.numberOfPads) 93 | ] 94 | } 95 | 96 | @objc private func sliderValueChanged(_ slider: UISlider) { 97 | beatsPerMinute = slider.value 98 | endLoop() 99 | startLoop() 100 | } 101 | 102 | // MARK: - Layout 103 | 104 | private func setupConstraints() { 105 | let spacing: CGFloat = 16 106 | 107 | NSLayoutConstraint.activate([ 108 | collectionView.leadingAnchor.constraint(equalTo: view.leadingAnchor), 109 | collectionView.trailingAnchor.constraint(equalTo: view.trailingAnchor), 110 | collectionView.topAnchor.constraint(equalTo: view.topAnchor), 111 | collectionView.bottomAnchor.constraint(equalTo: bpmSlider.topAnchor, constant: -spacing * 2), 112 | 113 | bpmSlider.bottomAnchor.constraint(equalTo: view.bottomAnchor, constant: -spacing * 3), 114 | bpmSlider.leadingAnchor.constraint(equalTo: collectionView.leadingAnchor, constant: spacing), 115 | bpmSlider.trailingAnchor.constraint(equalTo: collectionView.trailingAnchor, constant: -spacing) 116 | ]) 117 | } 118 | 119 | // MARK: - Timer 120 | 121 | private func startLoop() { 122 | timer = Timer.scheduledTimer( 123 | timeInterval: timeInterval, 124 | target: self, 125 | selector: #selector(update), 126 | userInfo: nil, 127 | repeats: true 128 | ) 129 | } 130 | 131 | private func endLoop() { 132 | timer?.invalidate() 133 | timer = nil 134 | } 135 | 136 | @objc private func update() { 137 | currentPad += 1 138 | 139 | if currentPad == numberOfPads { 140 | currentPad = 0 141 | } 142 | 143 | let nextCell = collectionView.cellForItem( 144 | at: IndexPath(item: currentPad, section: 0), 145 | type: DrumPadCollectionViewCell.self 146 | ) 147 | 148 | nextCell?.flash(withDuration: timeInterval) 149 | 150 | for (_, instrumentComposition) in compositions.enumerated() { 151 | if instrumentComposition.value[currentPad] { 152 | player.play(instrument: instrumentComposition.key) 153 | } 154 | } 155 | } 156 | } 157 | 158 | // MARK: - UICollectionViewDataSource 159 | 160 | extension DrumPadViewController: UICollectionViewDataSource { 161 | func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { 162 | return numberOfPads 163 | } 164 | 165 | func collectionView(_ collectionView: UICollectionView, 166 | cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { 167 | let cell = collectionView.dequeue(type: DrumPadCollectionViewCell.self, indexPath: indexPath) 168 | cell.contentView.backgroundColor = instrument.color 169 | cell.updateOverlayVisibility(isVisible: compositions[instrument]?[indexPath.item] ?? false) 170 | return cell 171 | } 172 | } 173 | 174 | // MARK: - UICollectionViewDelegate 175 | 176 | extension DrumPadViewController: UICollectionViewDelegateFlowLayout { 177 | func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) { 178 | let pad = indexPath.item 179 | let currentValue = compositions[instrument]?[pad] ?? false 180 | let newValue = !currentValue 181 | compositions[instrument]?[pad] = newValue 182 | 183 | let cell = collectionView.cellForItem( 184 | at: IndexPath(item: pad, section: 0), 185 | type: DrumPadCollectionViewCell.self 186 | ) 187 | 188 | cell?.updateOverlayVisibility(isVisible: newValue) 189 | } 190 | 191 | func collectionView(_ collectionView: UICollectionView, 192 | layout collectionViewLayout: UICollectionViewLayout, 193 | sizeForItemAt indexPath: IndexPath) -> CGSize { 194 | let minParentSideSize = min(collectionView.frame.width, collectionView.frame.height) 195 | let width = calculateItemMeasurement(for: collectionView.frame.width) 196 | let height = calculateItemMeasurement(for: minParentSideSize) 197 | return CGSize(width: width, height: height) 198 | } 199 | 200 | private func calculateItemMeasurement(for parentSideSize: CGFloat) -> CGFloat { 201 | let itemsPerRow: CGFloat = 4 202 | return (parentSideSize - cellSpacing * (itemsPerRow - 1) - padSpacing * 2) / itemsPerRow 203 | } 204 | } 205 | 206 | // MARK: - Subviews factory 207 | 208 | private extension DrumPadViewController { 209 | func makeCollectionView() -> UICollectionView { 210 | let collectionView = UICollectionView(frame: .zero, collectionViewLayout: makeCollectionViewLayout()) 211 | collectionView.translatesAutoresizingMaskIntoConstraints = false 212 | collectionView.backgroundColor = .black 213 | collectionView.register(type: DrumPadCollectionViewCell.self) 214 | collectionView.delegate = self 215 | collectionView.dataSource = self 216 | return collectionView 217 | } 218 | 219 | func makeCollectionViewLayout() -> UICollectionViewLayout { 220 | let layout = UICollectionViewFlowLayout() 221 | layout.scrollDirection = .vertical 222 | layout.minimumInteritemSpacing = cellSpacing 223 | layout.minimumLineSpacing = cellSpacing 224 | layout.sectionInset = UIEdgeInsets( 225 | top: padSpacing, 226 | left: padSpacing, 227 | bottom: padSpacing, 228 | right: padSpacing 229 | ) 230 | return layout 231 | } 232 | } 233 | 234 | // MARK: - Private extensions 235 | 236 | private extension UICollectionView { 237 | func register(type: T.Type) { 238 | register(T.self, forCellWithReuseIdentifier: String(describing: T.self)) 239 | } 240 | 241 | func dequeue(type: T.Type, indexPath: IndexPath) -> T { 242 | if let cell = dequeueReusableCell(withReuseIdentifier: String(describing: T.self), for: indexPath) as? T { 243 | return cell 244 | } else { 245 | assertionFailure("Incorrect type of cell") 246 | return T.init() 247 | } 248 | } 249 | 250 | func cellForItem(at indexPath: IndexPath, type: T.Type) -> T? { 251 | return cellForItem(at: indexPath) as? T 252 | } 253 | } 254 | -------------------------------------------------------------------------------- /DrumMachine/Sources/ViewController.swift: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.swift 3 | // DrumMachine 4 | // 5 | // Created by Markov, Vadym on 06/09/2018. 6 | // Copyright © 2018 FINN.no AS. All rights reserved. 7 | // 8 | 9 | import UIKit 10 | 11 | final class ViewController: UIViewController { 12 | override func viewDidAppear(_ animated: Bool) { 13 | super.viewDidAppear(animated) 14 | let viewController = DrumsViewController() 15 | present(viewController, animated: true, completion: nil) 16 | } 17 | } 18 | 19 | -------------------------------------------------------------------------------- /GitHub/image.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/finn-labs/DrumMachine/1327d9e44d5fd7863b7859f2c6948dd543a552f5/GitHub/image.jpg -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # DrumMachine 2 | 3 | ![](https://raw.githubusercontent.com/finn-labs/DrumMachine/master/GitHub/image.jpg) 4 | 5 | ## Credits 6 | 7 | **Sounds used in the app:** 8 | 9 | * Kick: https://freesound.org/people/DWSD/sounds/171104/ 10 | * Snare: https://freesound.org/people/alexthegr81/sounds/212208/ 11 | * Hi-Hats: https://freesound.org/people/soneproject/sounds/271402/ 12 | * Cat: https://freesound.org/people/timtube/sounds/61259/ 13 | --------------------------------------------------------------------------------