Skip to content

Commit

Permalink
Merge pull request #43 from andersfischernielsen/preference-window
Browse files Browse the repository at this point in the history
Implemented settings view controller for transition punishments.
  • Loading branch information
andersfischernielsen authored Jun 14, 2019
2 parents 3e66c5f + 8271346 commit 7e34dfb
Show file tree
Hide file tree
Showing 4 changed files with 168 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Traktor Transition Finder.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

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

/* Begin PBXFileReference section */
710B625C22B370E8004A018D /* PreferencesViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PreferencesViewController.swift; sourceTree = "<group>"; };
711BA07C22A093820010597F /* SongToSongViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SongToSongViewController.swift; sourceTree = "<group>"; };
714B125A22A4F9AE00113453 /* StateController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StateController.swift; sourceTree = "<group>"; };
715382D0229B736200DA997B /* SWXMLHash.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SWXMLHash.framework; path = Carthage/Build/Mac/SWXMLHash.framework; sourceTree = "<group>"; };
Expand Down Expand Up @@ -85,6 +87,7 @@
CD6B9F550FE276A90A203CE4 /* Traktor_Transition_Finder.entitlements */,
CD6B9923D82C029077AA100C /* AppDelegate.swift */,
CD6B942A864A42F178FC7F83 /* Main.storyboard */,
710B625C22B370E8004A018D /* PreferencesViewController.swift */,
CD6B97E49566A2DA258C0941 /* DragDropViewController.swift */,
711BA07C22A093820010597F /* SongToSongViewController.swift */,
71720D3C229FA15600BBCD14 /* CurrentlySelectedView.swift */,
Expand Down Expand Up @@ -188,6 +191,7 @@
CD6B9B58712D2D4761E92BF5 /* DestinationView.swift in Sources */,
711BA07D22A093820010597F /* SongToSongViewController.swift in Sources */,
71E83F3B2295141500E79900 /* TransitionTableCellView.swift in Sources */,
710B625D22B370E8004A018D /* PreferencesViewController.swift in Sources */,
71720D3D229FA15600BBCD14 /* CurrentlySelectedView.swift in Sources */,
71720D3A229F95FB00BBCD14 /* BreadCrumb.swift in Sources */,
CD6B9CC4A254B1BC8375B68C /* Graph.swift in Sources */,
Expand Down
121 changes: 119 additions & 2 deletions Traktor Transition Finder/Base.lproj/Main.storyboard
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="VOq-y0-SEH"/>
<menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW"/>
<menuItem title="Preferences…" keyEquivalent="," id="BOF-NM-1cW">
<connections>
<segue destination="3ob-jc-eDm" kind="show" id="2DP-OY-QfQ"/>
</connections>
</menuItem>
<menuItem isSeparatorItem="YES" id="wFC-TO-SCJ"/>
<menuItem title="Services" id="NMo-om-nkz">
<modifierMask key="keyEquivalentModifierMask"/>
Expand Down Expand Up @@ -209,7 +213,7 @@
<customObject id="YLy-65-1bz" customClass="NSFontManager"/>
<customObject id="Ady-hI-5gd" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="519" y="-302"/>
<point key="canvasLocation" x="521" y="-308"/>
</scene>
<!--Window Controller-->
<scene sceneID="R2V-B0-nI4">
Expand Down Expand Up @@ -255,6 +259,119 @@
</objects>
<point key="canvasLocation" x="792" y="246"/>
</scene>
<!--Window Controller-->
<scene sceneID="NBF-l9-a5o">
<objects>
<windowController id="3ob-jc-eDm" sceneMemberID="viewController">
<window key="window" title="Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" releasedWhenClosed="NO" visibleAtLaunch="NO" frameAutosaveName="" animationBehavior="default" tabbingMode="disallowed" id="xbg-bh-u6H">
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
<rect key="contentRect" x="196" y="249" width="280" height="160"/>
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="900"/>
<value key="maxSize" type="size" width="280" height="160"/>
<connections>
<outlet property="delegate" destination="3ob-jc-eDm" id="4Ld-3f-9Ck"/>
</connections>
</window>
<connections>
<segue destination="Qbb-Wz-0PT" kind="relationship" relationship="window.shadowedContentViewController" id="RGN-Rn-6qc"/>
</connections>
</windowController>
<customObject id="Ic1-VV-4Bv" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1283" y="-302"/>
</scene>
<!--Preferences View Controller-->
<scene sceneID="VFq-ZJ-niJ">
<objects>
<viewController id="Qbb-Wz-0PT" customClass="PreferencesViewController" customModule="Traktor_Transition_Finder" customModuleProvider="target" sceneMemberID="viewController">
<view key="view" id="399-Lw-MCz">
<rect key="frame" x="0.0" y="0.0" width="280" height="160"/>
<autoresizingMask key="autoresizingMask"/>
<subviews>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="6dx-8m-Fr3">
<rect key="frame" x="18" y="123" width="133" height="17"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Bad Key Punishment:" id="Way-XD-enb">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="RDo-eu-kFJ">
<rect key="frame" x="18" y="53" width="154" height="17"/>
<textFieldCell key="cell" lineBreakMode="clipping" title="Half-Tempo Punishment:" id="iSU-rn-phF">
<font key="font" usesAppearanceFont="YES"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<slider verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="FRw-R6-yec">
<rect key="frame" x="18" y="98" width="133" height="19"/>
<constraints>
<constraint firstAttribute="width" constant="129" id="3y5-wj-STx"/>
</constraints>
<sliderCell key="cell" continuous="YES" state="on" alignment="left" maxValue="40" doubleValue="25" tickMarkPosition="above" sliderType="linear" id="2EF-gz-91O"/>
<connections>
<action selector="badKeyPunishmentSliderChanged:" target="Qbb-Wz-0PT" id="p1a-SX-7G7"/>
</connections>
</slider>
<slider verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="Pcm-sn-2lf">
<rect key="frame" x="18" y="28" width="133" height="19"/>
<constraints>
<constraint firstAttribute="width" constant="129" id="Jny-Ua-uNV"/>
</constraints>
<sliderCell key="cell" continuous="YES" state="on" alignment="left" maxValue="40" doubleValue="6" tickMarkPosition="above" sliderType="linear" id="qW7-Y9-Kzh"/>
<connections>
<action selector="halfTempoPunishmentSliderChanged:" target="Qbb-Wz-0PT" id="3zf-3B-QbT"/>
</connections>
</slider>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="AgZ-CH-gEh">
<rect key="frame" x="157" y="99" width="8" height="17"/>
<textFieldCell key="cell" lineBreakMode="clipping" title=" " id="dWf-v9-h2O">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" translatesAutoresizingMaskIntoConstraints="NO" id="7hd-wf-PAZ">
<rect key="frame" x="157" y="29" width="8" height="17"/>
<textFieldCell key="cell" lineBreakMode="clipping" title=" " id="jPI-3L-goc">
<font key="font" metaFont="system"/>
<color key="textColor" name="labelColor" catalog="System" colorSpace="catalog"/>
<color key="backgroundColor" name="textBackgroundColor" catalog="System" colorSpace="catalog"/>
</textFieldCell>
</textField>
</subviews>
<constraints>
<constraint firstItem="6dx-8m-Fr3" firstAttribute="leading" secondItem="399-Lw-MCz" secondAttribute="leading" constant="20" id="2cR-WB-qml"/>
<constraint firstItem="7hd-wf-PAZ" firstAttribute="top" secondItem="RDo-eu-kFJ" secondAttribute="bottom" constant="7" id="99E-eF-w6Q"/>
<constraint firstItem="RDo-eu-kFJ" firstAttribute="leading" secondItem="399-Lw-MCz" secondAttribute="leading" constant="20" id="LYB-6H-kq5"/>
<constraint firstItem="Pcm-sn-2lf" firstAttribute="top" secondItem="RDo-eu-kFJ" secondAttribute="bottom" constant="8" id="Ogn-Py-cck"/>
<constraint firstItem="7hd-wf-PAZ" firstAttribute="leading" secondItem="Pcm-sn-2lf" secondAttribute="trailing" constant="10" id="a7N-Zx-TDD"/>
<constraint firstItem="AgZ-CH-gEh" firstAttribute="leading" secondItem="FRw-R6-yec" secondAttribute="trailing" constant="10" id="arS-L3-nSr"/>
<constraint firstItem="AgZ-CH-gEh" firstAttribute="top" secondItem="6dx-8m-Fr3" secondAttribute="bottom" constant="7" id="cMI-c8-EXz"/>
<constraint firstItem="FRw-R6-yec" firstAttribute="leading" secondItem="399-Lw-MCz" secondAttribute="leading" constant="20" id="cac-0X-hwx"/>
<constraint firstAttribute="trailing" relation="lessThanOrEqual" secondItem="RDo-eu-kFJ" secondAttribute="trailing" constant="180" id="cgu-si-q2J"/>
<constraint firstItem="Pcm-sn-2lf" firstAttribute="leading" secondItem="399-Lw-MCz" secondAttribute="leading" constant="20" id="dA2-Hi-N5x"/>
<constraint firstAttribute="trailing" relation="lessThanOrEqual" secondItem="7hd-wf-PAZ" secondAttribute="trailing" constant="158" id="eW2-mJ-p9L"/>
<constraint firstItem="RDo-eu-kFJ" firstAttribute="top" secondItem="6dx-8m-Fr3" secondAttribute="bottom" constant="53" id="jzb-eJ-qzk"/>
<constraint firstItem="6dx-8m-Fr3" firstAttribute="top" secondItem="399-Lw-MCz" secondAttribute="top" constant="20" id="vGq-QL-Q1v"/>
<constraint firstItem="FRw-R6-yec" firstAttribute="top" secondItem="6dx-8m-Fr3" secondAttribute="bottom" constant="8" id="w9I-ID-FEP"/>
<constraint firstAttribute="trailing" relation="lessThanOrEqual" secondItem="6dx-8m-Fr3" secondAttribute="trailing" constant="201" id="xTQ-Y1-cTQ"/>
<constraint firstAttribute="trailing" relation="lessThanOrEqual" secondItem="AgZ-CH-gEh" secondAttribute="trailing" constant="158" id="ymd-WX-iYV"/>
</constraints>
</view>
<connections>
<outlet property="badKeyPunishmentLabel" destination="AgZ-CH-gEh" id="mjk-gE-XLY"/>
<outlet property="badKeyPunishmentSlider" destination="FRw-R6-yec" id="VZd-DA-uKE"/>
<outlet property="halfTempoPunishmentLabel" destination="7hd-wf-PAZ" id="Btr-bU-KJG"/>
<outlet property="halfTempoPunishmentSlider" destination="Pcm-sn-2lf" id="6vK-P6-6NC"/>
</connections>
</viewController>
<customObject id="V63-dM-0Xs" userLabel="First Responder" customClass="NSResponder" sceneMemberID="firstResponder"/>
</objects>
<point key="canvasLocation" x="1283" y="172"/>
</scene>
<!--Drag Drop View Controller-->
<scene sceneID="hIz-AP-VOD">
<objects>
Expand Down
6 changes: 4 additions & 2 deletions Traktor Transition Finder/Graph.swift
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,11 @@ class Graph {
///Calculate weights for a (Song * Edge list) array.
///Create a graph (represented as a Song * Edge list array) from a Song list.
static func buildGraph(list: [Song], numberOfEdges: Int?) -> [String: (Song, [Edge])] {
let badKeyUserPreference = UserDefaults.standard.double(forKey: "badKeyPunishment")
let halfTempoUserPreference = UserDefaults.standard.double(forKey: "halfTempoPunishment")
//The "punishment" for having a bad key transition/being a harder transition.
let BADKEYWEIGHT: Double = 25.0
let HALFTEMPO: Double = 6.0
let BADKEYWEIGHT = badKeyUserPreference == 0 ? 25.0 : badKeyUserPreference
let HALFTEMPO = halfTempoUserPreference == 0 ? 6.0 : halfTempoUserPreference

func generateEdgesForSong(song: Song, songs: [Song]) -> (Song, [Edge]) {
func createEdgesFromSong(songs: [Song]) -> (Song, [Edge]) {
Expand Down
41 changes: 41 additions & 0 deletions Traktor Transition Finder/PreferencesViewController.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
//
// PreferencesViewController.swift
// Traktor Transition Finder
//
// Created by Anders Fischer-Nielsen on 14/06/2019.
// Copyright © 2019 Anders Fischer-Nielsen. All rights reserved.
//

import Foundation
import Cocoa

class PreferencesViewController: NSViewController {
@IBOutlet var badKeyPunishmentSlider: NSSlider!
@IBOutlet var halfTempoPunishmentSlider: NSSlider!
@IBOutlet var badKeyPunishmentLabel: NSTextField!
@IBOutlet var halfTempoPunishmentLabel: NSTextField!


@IBAction func badKeyPunishmentSliderChanged(_ sender: Any) {
let value = badKeyPunishmentSlider.doubleValue
UserDefaults.standard.set(value, forKey: "badKeyPunishment")
badKeyPunishmentLabel.stringValue = String(format: "%.2f", value)

}

@IBAction func halfTempoPunishmentSliderChanged(_ sender: Any) {
let value = halfTempoPunishmentSlider.doubleValue
UserDefaults.standard.set(value, forKey: "halfTempoPunishment")
halfTempoPunishmentLabel.stringValue = String(format: "%.2f", value)
}

override func viewDidLoad() {
if (UserDefaults.standard.double(forKey: "badKeyPunishment") != 0) {
badKeyPunishmentLabel.stringValue = String(format: "%.2f", UserDefaults.standard.double(forKey: "badKeyPunishment"))
}

if (UserDefaults.standard.double(forKey: "halfTempoPunishment") != 0) {
halfTempoPunishmentLabel.stringValue = String(format: "%.2f", UserDefaults.standard.double(forKey: "halfTempoPunishment"))
}
}
}

0 comments on commit 7e34dfb

Please sign in to comment.