Skip to content

Commit

Permalink
added eqMac2 legacy preset import and sorting presets by name
Browse files Browse the repository at this point in the history
  • Loading branch information
nodeful committed Jun 20, 2020
1 parent ce684e5 commit 0b44850
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,15 @@ class AdvancedEqualizerDataBus: DataBus {
return nil
}

self.on(.GET, "/presets/import-legacy/available") { data, _ in
return "Yes"
}

self.on(.GET, "/presets/import-legacy") { data, _ in
// TODO: Implement
let presets = eqMac2.get10BandPresets()
for preset in presets {
_ = AdvancedEqualizer.createPreset(name: preset.name, gains: preset.gains)
}
return "Imported"
}

Expand Down
40 changes: 40 additions & 0 deletions native/app/Source/Helpers/eqMac2.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// eqMac2.swift
// eqMac
//
// Created by Romans Kisils on 20/06/2020.
// Copyright © 2020 Romans Kisils. All rights reserved.
//

import Foundation


class eqMac2 {

static var defaults: Dictionary<String, Any>? {
return UserDefaults(suiteName: "com.bitgapp.eqMac2")?.dictionaryRepresentation()
}

static func get10BandPresets () -> [AdvancedEqualizerPreset] {
if defaults != nil, let presets = defaults!["kStoragePresets"] as? Dictionary<String, Dictionary<String, Any>> {
var result: [AdvancedEqualizerPreset] = []
for (name, preset) in presets {
if let gains = preset["gains"] as? [Double] {
if gains.count == 10 {
result.append(AdvancedEqualizerPreset(
id: UUID().uuidString,
name: name,
isDefault: false,
gains: AdvancedEqualizerPresetGains(
global: 0,
bands: gains.map { Utilities.mapValue(value: $0, inMin: -1, inMax: 1, outMin: -24, outMax: 24) }
)
))
}
}
}
return result
}
return []
}
}
4 changes: 4 additions & 0 deletions native/app/eqMac.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@
E0C5629320A39651000902ED /* Bridge.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0C5629220A39651000902ED /* Bridge.swift */; };
E0C5629920A75BAD000902ED /* Storage.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0C5629820A75BAD000902ED /* Storage.swift */; };
E0C8F78621D3B6590023B1E5 /* UIDataBus.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0C8F78521D3B6590023B1E5 /* UIDataBus.swift */; };
E0D1A0DA249E191700BBC742 /* eqMac2.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0D1A0D9249E191700BBC742 /* eqMac2.swift */; };
E0D5F88722DD20F800499250 /* SettingsState.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0D5F88622DD20F800499250 /* SettingsState.swift */; };
E0DDF3FA2188390300B37E77 /* Alert.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0DDF3F92188390300B37E77 /* Alert.swift */; };
E0E2CFF72104EA7A002DC989 /* Equalizers.swift in Sources */ = {isa = PBXBuildFile; fileRef = E0E2CFF62104EA7A002DC989 /* Equalizers.swift */; };
Expand Down Expand Up @@ -214,6 +215,7 @@
E0C5629220A39651000902ED /* Bridge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Bridge.swift; sourceTree = "<group>"; };
E0C5629820A75BAD000902ED /* Storage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Storage.swift; sourceTree = "<group>"; };
E0C8F78521D3B6590023B1E5 /* UIDataBus.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = UIDataBus.swift; sourceTree = "<group>"; };
E0D1A0D9249E191700BBC742 /* eqMac2.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = eqMac2.swift; sourceTree = "<group>"; };
E0D5F88622DD20F800499250 /* SettingsState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsState.swift; sourceTree = "<group>"; };
E0DDF3F92188390300B37E77 /* Alert.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Alert.swift; sourceTree = "<group>"; };
E0DDF3FC2189021300B37E77 /* install_driver.sh */ = {isa = PBXFileReference; lastKnownFileType = text.script.sh; path = install_driver.sh; sourceTree = "<group>"; };
Expand Down Expand Up @@ -418,6 +420,7 @@
E02FF91722C8E87D0051342A /* Time.swift */,
E0ECA88923B7F816002AFBF0 /* ExceptionCatcher.h */,
E0AAD9D9249C109000D58099 /* SwiftyPing.swift */,
E0D1A0D9249E191700BBC742 /* eqMac2.swift */,
);
path = Helpers;
sourceTree = "<group>";
Expand Down Expand Up @@ -875,6 +878,7 @@
E021BCE722313F1E004921FF /* SettingsDataBus.swift in Sources */,
E00C595923BBB8B000C7B8B6 /* RingBufferTimeBounds.swift in Sources */,
E017A0091FF055B50019BBF1 /* User.swift in Sources */,
E0D1A0DA249E191700BBC742 /* eqMac2.swift in Sources */,
E0E8B62F20EEB6A900DE905C /* EffectsState.swift in Sources */,
E0D5F88722DD20F800499250 /* SettingsState.swift in Sources */,
E01B1BB9235E454500CC58E5 /* InputSource.swift in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,16 @@ export class AdvancedEqualizerComponent extends EqualizerComponent implements On
}
], [
this.ShowDefaultPresetsCheckbox
// {
// key: 'import-legacy-presets',
// type: 'button',
// label: 'Import eqMac2 Presets',
// action: () => {}
// }
]]
private _presets: AdvancedEqualizerPreset[]
@Output() presetsChange = new EventEmitter<AdvancedEqualizerPreset[]>()
set presets (newPresets: AdvancedEqualizerPreset[]) {
this._presets = newPresets
this._presets =
[
newPresets.find(p => p.id === 'manual'),
newPresets.find(p => p.id === 'flat'),
...newPresets.filter(p => !['manual', 'flat'].includes(p.id)).sort((a, b) => a.name > b.name ? 1 : -1)
]
this.presetsChange.emit(this.presets)
}
get presets () { return this._presets }
Expand Down Expand Up @@ -105,7 +104,10 @@ export class AdvancedEqualizerComponent extends EqualizerComponent implements On
private transition: TransitionService,
private change: ChangeDetectorRef,
private app: ApplicationService
) { super() }
) {
super()
this.getImportLegacyAvailable()
}

async ngOnInit () {
await this.sync()
Expand All @@ -119,6 +121,23 @@ export class AdvancedEqualizerComponent extends EqualizerComponent implements On
])
}

private async getImportLegacyAvailable () {
if (await this.service.getImportLegacyAvailable()) {
this.settings[1].push(
{
key: 'import-legacy-presets',
type: 'button',
label: 'Import eqMac2 Presets',
action: async () => {
await this.service.importLegacy()
if (this.settingsDialog) {
this.settingsDialog.close()
}
}
}
)
}
}
private async syncPresets () {
const [ presets, selectedPreset ] = await Promise.all([
this.service.getPresets(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,22 @@ export class AdvancedEqualizerService extends EqualizersService {
return this.request({ method: 'DELETE', endpoint: `/presets`, data: { ...preset } })
}

async getImportLegacyAvailable () {
return new Promise(async (resolve) => {
setTimeout(() => resolve(false), 1000)
try {
await this.request({ method: 'GET', endpoint: '/presets/import-legacy/available' })
resolve(true)
} catch (err) {
resolve(false)
}
})
}

async importLegacy () {
return this.request({ method: 'GET', endpoint: '/presets/import-legacy' })
}

importPresets () {
return this.request({ method: 'GET', endpoint: '/presets/import' })
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ export class BasicEqualizerComponent extends EqualizerComponent implements OnIni
private _presets: BasicEqualizerPreset[]
@Output() presetsChange = new EventEmitter<BasicEqualizerPreset[]>()
set presets (newPresets: BasicEqualizerPreset[]) {
this._presets = newPresets
this._presets =
[
newPresets.find(p => p.id === 'manual'),
newPresets.find(p => p.id === 'flat'),
...newPresets.filter(p => !['manual', 'flat'].includes(p.id)).sort((a, b) => a.name > b.name ? 1 : -1)
]
this.presetsChange.emit(this.presets)
}
get presets () { return this._presets }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Option, Options } from 'src/app/components/options/options.component'
import { EqualizerPreset } from './presets/equalizer-presets.component'
import { Input } from '@angular/core'
import { MatDialogRef } from '@angular/material'
import { OptionsDialogComponent } from '../../../components/options-dialog/options-dialog.component'

export abstract class EqualizerComponent {
@Input() animationDuration = 500
@Input() animationFps = 30

@Input() settingsDialog: MatDialogRef<OptionsDialogComponent, any>
abstract settings: Options
abstract async sync ()
async selected () {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,12 @@
[enabled]="enabled" class="equalizer"
(presetsChange)="presets = $event" (selectedPresetChange)="selectedPreset = $event"
[animationDuration]="animationDuration" [animationFps]="animationFps"
[settingsDialog]="settingsDialog"
></eqm-basic-equalizer>
<eqm-advanced-equalizer #advancedEqualizer *eqmCarouselItem="'Advanced'"
[enabled]="enabled" class="equalizer"
(presetsChange)="presets = $event" (selectedPresetChange)="selectedPreset = $event"
[animationDuration]="animationDuration" [animationFps]="animationFps"
[settingsDialog]="settingsDialog"
></eqm-advanced-equalizer>
</eqm-carousel>

0 comments on commit 0b44850

Please sign in to comment.