Skip to content

Commit 7e34dfb

Browse files
Merge pull request #43 from andersfischernielsen/preference-window
Implemented settings view controller for transition punishments.
2 parents 3e66c5f + 8271346 commit 7e34dfb

File tree

4 files changed

+168
-4
lines changed

4 files changed

+168
-4
lines changed

Traktor Transition Finder.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
710B625D22B370E8004A018D /* PreferencesViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 710B625C22B370E8004A018D /* PreferencesViewController.swift */; };
1011
711BA07D22A093820010597F /* SongToSongViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 711BA07C22A093820010597F /* SongToSongViewController.swift */; };
1112
714B125B22A4F9AE00113453 /* StateController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 714B125A22A4F9AE00113453 /* StateController.swift */; };
1213
715382D2229B736200DA997B /* SWXMLHash.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 715382D0229B736200DA997B /* SWXMLHash.framework */; };
@@ -38,6 +39,7 @@
3839
/* End PBXCopyFilesBuildPhase section */
3940

4041
/* Begin PBXFileReference section */
42+
710B625C22B370E8004A018D /* PreferencesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesViewController.swift; sourceTree = "<group>"; };
4143
711BA07C22A093820010597F /* SongToSongViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SongToSongViewController.swift; sourceTree = "<group>"; };
4244
714B125A22A4F9AE00113453 /* StateController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StateController.swift; sourceTree = "<group>"; };
4345
715382D0229B736200DA997B /* SWXMLHash.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SWXMLHash.framework; path = Carthage/Build/Mac/SWXMLHash.framework; sourceTree = "<group>"; };
@@ -85,6 +87,7 @@
8587
CD6B9F550FE276A90A203CE4 /* Traktor_Transition_Finder.entitlements */,
8688
CD6B9923D82C029077AA100C /* AppDelegate.swift */,
8789
CD6B942A864A42F178FC7F83 /* Main.storyboard */,
90+
710B625C22B370E8004A018D /* PreferencesViewController.swift */,
8891
CD6B97E49566A2DA258C0941 /* DragDropViewController.swift */,
8992
711BA07C22A093820010597F /* SongToSongViewController.swift */,
9093
71720D3C229FA15600BBCD14 /* CurrentlySelectedView.swift */,
@@ -188,6 +191,7 @@
188191
CD6B9B58712D2D4761E92BF5 /* DestinationView.swift in Sources */,
189192
711BA07D22A093820010597F /* SongToSongViewController.swift in Sources */,
190193
71E83F3B2295141500E79900 /* TransitionTableCellView.swift in Sources */,
194+
710B625D22B370E8004A018D /* PreferencesViewController.swift in Sources */,
191195
71720D3D229FA15600BBCD14 /* CurrentlySelectedView.swift in Sources */,
192196
71720D3A229F95FB00BBCD14 /* BreadCrumb.swift in Sources */,
193197
CD6B9CC4A254B1BC8375B68C /* Graph.swift in Sources */,

Traktor Transition Finder/Base.lproj/Main.storyboard

Lines changed: 119 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323
</connections>
2424
</menuItem>
2525
<menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/>
26-
<menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW"/>
26+
<menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW">
27+
<connections>
28+
<segue destination="3ob-jc-eDm" kind="show" id="2DP-OY-QfQ"/>
29+
</connections>
30+
</menuItem>
2731
<menuItem isSeparatorItem="YES" id="wFC-TO-SCJ"/>
2832
<menuItem title="Services" id="NMo-om-nkz">
2933
<modifierMask key="keyEquivalentModifierMask"/>
@@ -209,7 +213,7 @@
209213
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
210214
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
211215
</objects>
212-
<point key="canvasLocation" x="519" y="-302"/>
216+
<point key="canvasLocation" x="521" y="-308"/>
213217
</scene>
214218
<!--Window Controller-->
215219
<scene sceneID="R2V-B0-nI4">
@@ -255,6 +259,119 @@
255259
</objects>
256260
<point key="canvasLocation" x="792" y="246"/>
257261
</scene>
262+
<!--Window Controller-->
263+
<scene sceneID="NBF-l9-a5o">
264+
<objects>
265+
<windowController id="3ob-jc-eDm" sceneMemberID="viewController">
266+
<window key="window" title="Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" tabbingMode="disallowed" id="xbg-bh-u6H">
267+
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
268+
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
269+
<rect key="contentRect" x="196" y="249" width="280" height="160"/>
270+
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="900"/>
271+
<value key="maxSize" type="size" width="280" height="160"/>
272+
<connections>
273+
<outlet property="delegate" destination="3ob-jc-eDm" id="4Ld-3f-9Ck"/>
274+
</connections>
275+
</window>
276+
<connections>
277+
<segue destination="Qbb-Wz-0PT" kind="relationship" relationship="window.shadowedContentViewController" id="RGN-Rn-6qc"/>
278+
</connections>
279+
</windowController>
280+
<customObject id="Ic1-VV-4Bv" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
281+
</objects>
282+
<point key="canvasLocation" x="1283" y="-302"/>
283+
</scene>
284+
<!--Preferences View Controller-->
285+
<scene sceneID="VFq-ZJ-niJ">
286+
<objects>
287+
<viewController id="Qbb-Wz-0PT" customClass="PreferencesViewController" customModule="Traktor_Transition_Finder" customModuleProvider="target" sceneMemberID="viewController">
288+
<view key="view" id="399-Lw-MCz">
289+
<rect key="frame" x="0.0" y="0.0" width="280" height="160"/>
290+
<autoresizingMask key="autoresizingMask"/>
291+
<subviews>
292+
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="6dx-8m-Fr3">
293+
<rect key="frame" x="18" y="123" width="133" height="17"/>
294+
<textFieldCell key="cell" lineBreakMode="clipping" title="Bad Key Punishment:" id="Way-XD-enb">
295+
<font key="font" usesAppearanceFont="YES"/>
296+
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
297+
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
298+
</textFieldCell>
299+
</textField>
300+
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="RDo-eu-kFJ">
301+
<rect key="frame" x="18" y="53" width="154" height="17"/>
302+
<textFieldCell key="cell" lineBreakMode="clipping" title="Half-Tempo Punishment:" id="iSU-rn-phF">
303+
<font key="font" usesAppearanceFont="YES"/>
304+
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
305+
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
306+
</textFieldCell>
307+
</textField>
308+
<slider verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="FRw-R6-yec">
309+
<rect key="frame" x="18" y="98" width="133" height="19"/>
310+
<constraints>
311+
<constraint firstAttribute="width" constant="129" id="3y5-wj-STx"/>
312+
</constraints>
313+
<sliderCell key="cell" continuous="YES" state="on" alignment="left" maxValue="40" doubleValue="25" tickMarkPosition="above" sliderType="linear" id="2EF-gz-91O"/>
314+
<connections>
315+
<action selector="badKeyPunishmentSliderChanged:" target="Qbb-Wz-0PT" id="p1a-SX-7G7"/>
316+
</connections>
317+
</slider>
318+
<slider verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Pcm-sn-2lf">
319+
<rect key="frame" x="18" y="28" width="133" height="19"/>
320+
<constraints>
321+
<constraint firstAttribute="width" constant="129" id="Jny-Ua-uNV"/>
322+
</constraints>
323+
<sliderCell key="cell" continuous="YES" state="on" alignment="left" maxValue="40" doubleValue="6" tickMarkPosition="above" sliderType="linear" id="qW7-Y9-Kzh"/>
324+
<connections>
325+
<action selector="halfTempoPunishmentSliderChanged:" target="Qbb-Wz-0PT" id="3zf-3B-QbT"/>
326+
</connections>
327+
</slider>
328+
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="AgZ-CH-gEh">
329+
<rect key="frame" x="157" y="99" width="8" height="17"/>
330+
<textFieldCell key="cell" lineBreakMode="clipping" title=" " id="dWf-v9-h2O">
331+
<font key="font" metaFont="system"/>
332+
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
333+
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
334+
</textFieldCell>
335+
</textField>
336+
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="7hd-wf-PAZ">
337+
<rect key="frame" x="157" y="29" width="8" height="17"/>
338+
<textFieldCell key="cell" lineBreakMode="clipping" title=" " id="jPI-3L-goc">
339+
<font key="font" metaFont="system"/>
340+
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
341+
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
342+
</textFieldCell>
343+
</textField>
344+
</subviews>
345+
<constraints>
346+
<constraint firstItem="6dx-8m-Fr3" firstAttribute="leading" secondItem="399-Lw-MCz" secondAttribute="leading" constant="20" id="2cR-WB-qml"/>
347+
<constraint firstItem="7hd-wf-PAZ" firstAttribute="top" secondItem="RDo-eu-kFJ" secondAttribute="bottom" constant="7" id="99E-eF-w6Q"/>
348+
<constraint firstItem="RDo-eu-kFJ" firstAttribute="leading" secondItem="399-Lw-MCz" secondAttribute="leading" constant="20" id="LYB-6H-kq5"/>
349+
<constraint firstItem="Pcm-sn-2lf" firstAttribute="top" secondItem="RDo-eu-kFJ" secondAttribute="bottom" constant="8" id="Ogn-Py-cck"/>
350+
<constraint firstItem="7hd-wf-PAZ" firstAttribute="leading" secondItem="Pcm-sn-2lf" secondAttribute="trailing" constant="10" id="a7N-Zx-TDD"/>
351+
<constraint firstItem="AgZ-CH-gEh" firstAttribute="leading" secondItem="FRw-R6-yec" secondAttribute="trailing" constant="10" id="arS-L3-nSr"/>
352+
<constraint firstItem="AgZ-CH-gEh" firstAttribute="top" secondItem="6dx-8m-Fr3" secondAttribute="bottom" constant="7" id="cMI-c8-EXz"/>
353+
<constraint firstItem="FRw-R6-yec" firstAttribute="leading" secondItem="399-Lw-MCz" secondAttribute="leading" constant="20" id="cac-0X-hwx"/>
354+
<constraint firstAttribute="trailing" relation="lessThanOrEqual" secondItem="RDo-eu-kFJ" secondAttribute="trailing" constant="180" id="cgu-si-q2J"/>
355+
<constraint firstItem="Pcm-sn-2lf" firstAttribute="leading" secondItem="399-Lw-MCz" secondAttribute="leading" constant="20" id="dA2-Hi-N5x"/>
356+
<constraint firstAttribute="trailing" relation="lessThanOrEqual" secondItem="7hd-wf-PAZ" secondAttribute="trailing" constant="158" id="eW2-mJ-p9L"/>
357+
<constraint firstItem="RDo-eu-kFJ" firstAttribute="top" secondItem="6dx-8m-Fr3" secondAttribute="bottom" constant="53" id="jzb-eJ-qzk"/>
358+
<constraint firstItem="6dx-8m-Fr3" firstAttribute="top" secondItem="399-Lw-MCz" secondAttribute="top" constant="20" id="vGq-QL-Q1v"/>
359+
<constraint firstItem="FRw-R6-yec" firstAttribute="top" secondItem="6dx-8m-Fr3" secondAttribute="bottom" constant="8" id="w9I-ID-FEP"/>
360+
<constraint firstAttribute="trailing" relation="lessThanOrEqual" secondItem="6dx-8m-Fr3" secondAttribute="trailing" constant="201" id="xTQ-Y1-cTQ"/>
361+
<constraint firstAttribute="trailing" relation="lessThanOrEqual" secondItem="AgZ-CH-gEh" secondAttribute="trailing" constant="158" id="ymd-WX-iYV"/>
362+
</constraints>
363+
</view>
364+
<connections>
365+
<outlet property="badKeyPunishmentLabel" destination="AgZ-CH-gEh" id="mjk-gE-XLY"/>
366+
<outlet property="badKeyPunishmentSlider" destination="FRw-R6-yec" id="VZd-DA-uKE"/>
367+
<outlet property="halfTempoPunishmentLabel" destination="7hd-wf-PAZ" id="Btr-bU-KJG"/>
368+
<outlet property="halfTempoPunishmentSlider" destination="Pcm-sn-2lf" id="6vK-P6-6NC"/>
369+
</connections>
370+
</viewController>
371+
<customObject id="V63-dM-0Xs" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
372+
</objects>
373+
<point key="canvasLocation" x="1283" y="172"/>
374+
</scene>
258375
<!--Drag Drop View Controller-->
259376
<scene sceneID="hIz-AP-VOD">
260377
<objects>

Traktor Transition Finder/Graph.swift

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,11 @@ class Graph {
150150
///Calculate weights for a (Song * Edge list) array.
151151
///Create a graph (represented as a Song * Edge list array) from a Song list.
152152
static func buildGraph(list: [Song], numberOfEdges: Int?) -> [String: (Song, [Edge])] {
153+
let badKeyUserPreference = UserDefaults.standard.double(forKey: "badKeyPunishment")
154+
let halfTempoUserPreference = UserDefaults.standard.double(forKey: "halfTempoPunishment")
153155
//The "punishment" for having a bad key transition/being a harder transition.
154-
let BADKEYWEIGHT: Double = 25.0
155-
let HALFTEMPO: Double = 6.0
156+
let BADKEYWEIGHT = badKeyUserPreference == 0 ? 25.0 : badKeyUserPreference
157+
let HALFTEMPO = halfTempoUserPreference == 0 ? 6.0 : halfTempoUserPreference
156158

157159
func generateEdgesForSong(song: Song, songs: [Song]) -> (Song, [Edge]) {
158160
func createEdgesFromSong(songs: [Song]) -> (Song, [Edge]) {
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
//
2+
// PreferencesViewController.swift
3+
// Traktor Transition Finder
4+
//
5+
// Created by Anders Fischer-Nielsen on 14/06/2019.
6+
// Copyright © 2019 Anders Fischer-Nielsen. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import Cocoa
11+
12+
class PreferencesViewController: NSViewController {
13+
@IBOutlet var badKeyPunishmentSlider: NSSlider!
14+
@IBOutlet var halfTempoPunishmentSlider: NSSlider!
15+
@IBOutlet var badKeyPunishmentLabel: NSTextField!
16+
@IBOutlet var halfTempoPunishmentLabel: NSTextField!
17+
18+
19+
@IBAction func badKeyPunishmentSliderChanged(_ sender: Any) {
20+
let value = badKeyPunishmentSlider.doubleValue
21+
UserDefaults.standard.set(value, forKey: "badKeyPunishment")
22+
badKeyPunishmentLabel.stringValue = String(format: "%.2f", value)
23+
24+
}
25+
26+
@IBAction func halfTempoPunishmentSliderChanged(_ sender: Any) {
27+
let value = halfTempoPunishmentSlider.doubleValue
28+
UserDefaults.standard.set(value, forKey: "halfTempoPunishment")
29+
halfTempoPunishmentLabel.stringValue = String(format: "%.2f", value)
30+
}
31+
32+
override func viewDidLoad() {
33+
if (UserDefaults.standard.double(forKey: "badKeyPunishment") != 0) {
34+
badKeyPunishmentLabel.stringValue = String(format: "%.2f", UserDefaults.standard.double(forKey: "badKeyPunishment"))
35+
}
36+
37+
if (UserDefaults.standard.double(forKey: "halfTempoPunishment") != 0) {
38+
halfTempoPunishmentLabel.stringValue = String(format: "%.2f", UserDefaults.standard.double(forKey: "halfTempoPunishment"))
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)