mirror of
https://github.com/kaythomas0/noisedash.git
synced 2025-11-11 19:06:20 +00:00
Fix sporadic validation, fix preferences bug
This commit is contained in:
@@ -59,32 +59,56 @@ module.exports = function () {
|
|||||||
} else {
|
} else {
|
||||||
const userVersion = row.user_version
|
const userVersion = row.user_version
|
||||||
|
|
||||||
if (userVersion < 1) {
|
db.serialize(() => {
|
||||||
db.run('ALTER TABLE samples ADD COLUMN fade_in REAL DEFAULT 0')
|
if (userVersion < 1) {
|
||||||
db.run('ALTER TABLE samples ADD COLUMN loop_points_enabled INTEGER DEFAULT 0')
|
db.run('ALTER TABLE samples ADD COLUMN fade_in REAL DEFAULT 0')
|
||||||
db.run('ALTER TABLE samples ADD COLUMN loop_start REAL DEFAULT 0')
|
db.run('ALTER TABLE samples ADD COLUMN loop_points_enabled INTEGER DEFAULT 0')
|
||||||
db.run('ALTER TABLE samples ADD COLUMN loop_end REAL DEFAULT 0')
|
db.run('ALTER TABLE samples ADD COLUMN loop_start REAL DEFAULT 0')
|
||||||
|
db.run('ALTER TABLE samples ADD COLUMN loop_end REAL DEFAULT 0')
|
||||||
|
|
||||||
db.run('PRAGMA user_version = 1')
|
db.run('PRAGMA user_version = 1')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userVersion < 2) {
|
if (userVersion < 2) {
|
||||||
db.run('ALTER TABLE users ADD COLUMN preferences TEXT DEFAULT "{}"')
|
db.run('ALTER TABLE users ADD COLUMN preferences TEXT DEFAULT "{}"')
|
||||||
|
|
||||||
db.run('PRAGMA user_version = 2')
|
db.run('PRAGMA user_version = 2')
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userVersion < 3) {
|
if (userVersion < 3) {
|
||||||
db.run('ALTER TABLE profiles_samples ADD COLUMN reverb_enabled INTEGER DEFAULT 0')
|
db.run('ALTER TABLE profiles_samples ADD COLUMN reverb_enabled INTEGER DEFAULT 0')
|
||||||
db.run('ALTER TABLE profiles_samples ADD COLUMN reverb_pre_delay REAL DEFAULT 0')
|
db.run('ALTER TABLE profiles_samples ADD COLUMN reverb_pre_delay REAL DEFAULT 0')
|
||||||
db.run('ALTER TABLE profiles_samples ADD COLUMN reverb_decay REAL DEFAULT 0')
|
db.run('ALTER TABLE profiles_samples ADD COLUMN reverb_decay REAL DEFAULT 0')
|
||||||
db.run('ALTER TABLE profiles_samples ADD COLUMN reverb_wet INTEGER DEFAULT 0')
|
db.run('ALTER TABLE profiles_samples ADD COLUMN reverb_wet INTEGER DEFAULT 0')
|
||||||
db.run('ALTER TABLE profiles_samples ADD COLUMN playback_mode TEXT DEFAULT "continuous"')
|
db.run('ALTER TABLE profiles_samples ADD COLUMN playback_mode TEXT DEFAULT "continuous"')
|
||||||
db.run('ALTER TABLE profiles_samples ADD COLUMN sporadic_min INTEGER DEFAULT 30')
|
db.run('ALTER TABLE profiles_samples ADD COLUMN sporadic_min INTEGER DEFAULT 30')
|
||||||
db.run('ALTER TABLE profiles_samples ADD COLUMN sporadic_max INTEGER DEFAULT 300')
|
db.run('ALTER TABLE profiles_samples ADD COLUMN sporadic_max INTEGER DEFAULT 300')
|
||||||
|
|
||||||
db.run('PRAGMA user_version = 3')
|
db.run('PRAGMA user_version = 3')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (userVersion < 4) {
|
||||||
|
db.all('SELECT preferences FROM users', (err, rows) => {
|
||||||
|
if (err) {
|
||||||
|
logger.error(err)
|
||||||
|
} else {
|
||||||
|
rows.forEach(row => {
|
||||||
|
if (row.preferences === '{}') {
|
||||||
|
db.run('UPDATE users SET preferences = ?',
|
||||||
|
['{"accentColor":{"alpha":1,"hex":"#607D8B","hexa":"#607D8BFF","hsla":{"h":200,"s":18,"l":46,"a":1},"hsva":{"h":200,"s":31,"v":55,"a":1},"hue":200,"rgba":{"r":96,"g":125,"b":139,"a":1}}}'],
|
||||||
|
(err) => {
|
||||||
|
if (err) {
|
||||||
|
logger.error(err)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
db.run('PRAGMA user_version = 4')
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -72,6 +72,8 @@ router.post('/users', (req, res) => {
|
|||||||
return res.sendStatus(500)
|
return res.sendStatus(500)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const defaultPreferences = '{"accentColor":{"alpha":1,"hex":"#607D8B","hexa":"#607D8BFF","hsla":{"h":200,"s":18,"l":46,"a":1},"hsva":{"h":200,"s":31,"v":55,"a":1},"hue":200,"rgba":{"r":96,"g":125,"b":139,"a":1}}}'
|
||||||
|
|
||||||
if (row.count !== 0) {
|
if (row.count !== 0) {
|
||||||
if (!req.user) {
|
if (!req.user) {
|
||||||
return res.sendStatus(401)
|
return res.sendStatus(401)
|
||||||
@@ -94,15 +96,16 @@ router.post('/users', (req, res) => {
|
|||||||
return res.sendStatus(500)
|
return res.sendStatus(500)
|
||||||
}
|
}
|
||||||
|
|
||||||
db.run(`INSERT INTO users (username, hashed_password, salt, name, is_admin, dark_mode, can_upload)
|
db.run(`INSERT INTO users (username, hashed_password, salt, name, is_admin, dark_mode, can_upload, preferences)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?)`, [
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, [
|
||||||
req.body.username,
|
req.body.username,
|
||||||
hashedPassword,
|
hashedPassword,
|
||||||
salt,
|
salt,
|
||||||
req.body.name,
|
req.body.name,
|
||||||
req.body.isAdmin,
|
req.body.isAdmin,
|
||||||
req.body.darkMode,
|
req.body.darkMode,
|
||||||
req.body.canUpload
|
req.body.canUpload,
|
||||||
|
defaultPreferences
|
||||||
], (err) => {
|
], (err) => {
|
||||||
if (err) {
|
if (err) {
|
||||||
logger.error(err)
|
logger.error(err)
|
||||||
@@ -125,15 +128,16 @@ router.post('/users', (req, res) => {
|
|||||||
return res.sendStatus(500)
|
return res.sendStatus(500)
|
||||||
}
|
}
|
||||||
|
|
||||||
db.run(`INSERT INTO users (username, hashed_password, salt, name, is_admin, dark_mode, can_upload)
|
db.run(`INSERT INTO users (username, hashed_password, salt, name, is_admin, dark_mode, can_upload, preferences)
|
||||||
VALUES (?, ?, ?, ?, ?, ?, ?)`, [
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`, [
|
||||||
req.body.username,
|
req.body.username,
|
||||||
hashedPassword,
|
hashedPassword,
|
||||||
salt,
|
salt,
|
||||||
req.body.name,
|
req.body.name,
|
||||||
req.body.isAdmin,
|
req.body.isAdmin,
|
||||||
req.body.darkMode,
|
req.body.darkMode,
|
||||||
req.body.canUpload
|
req.body.canUpload,
|
||||||
|
defaultPreferences
|
||||||
], function (err) {
|
], function (err) {
|
||||||
if (err) {
|
if (err) {
|
||||||
logger.error(err)
|
logger.error(err)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
|
|
||||||
<v-row justify="center">
|
<v-row justify="center">
|
||||||
<v-btn
|
<v-btn
|
||||||
:disabled="playDisabled || !isTimerValid || !isSporadicValid"
|
:disabled="playDisabled || !isTimerValid || (loadedSamples.length != 0 && !isSporadicValid)"
|
||||||
class="mx-3 mb-5"
|
class="mx-3 mb-5"
|
||||||
fab
|
fab
|
||||||
large
|
large
|
||||||
@@ -640,7 +640,7 @@
|
|||||||
v-if="canUpload"
|
v-if="canUpload"
|
||||||
cols="12"
|
cols="12"
|
||||||
>
|
>
|
||||||
<h2 class="display-1 font-weight-bold mb-7">
|
<h2 class="display-1 font-weight-bold mb-5">
|
||||||
Samples
|
Samples
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
@@ -776,7 +776,6 @@
|
|||||||
</v-row>
|
</v-row>
|
||||||
|
|
||||||
<v-row
|
<v-row
|
||||||
justify="center"
|
|
||||||
class="mb-5"
|
class="mb-5"
|
||||||
>
|
>
|
||||||
<v-radio-group
|
<v-radio-group
|
||||||
@@ -785,11 +784,11 @@
|
|||||||
mandatory
|
mandatory
|
||||||
>
|
>
|
||||||
<v-radio
|
<v-radio
|
||||||
label="Continuous"
|
label="Continuous (Looped)"
|
||||||
value="continuous"
|
value="continuous"
|
||||||
/>
|
/>
|
||||||
<v-radio
|
<v-radio
|
||||||
label="Sporadic"
|
label="Sporadic (Not Looped, Plays Randomly Within Interval"
|
||||||
value="sporadic"
|
value="sporadic"
|
||||||
/>
|
/>
|
||||||
</v-radio-group>
|
</v-radio-group>
|
||||||
@@ -807,7 +806,7 @@
|
|||||||
label="Sporadic Min"
|
label="Sporadic Min"
|
||||||
class="mx-3"
|
class="mx-3"
|
||||||
:disabled="sample.playbackMode != 'sporadic' || playDisabled"
|
:disabled="sample.playbackMode != 'sporadic' || playDisabled"
|
||||||
:rules="[validateSporadicRange(sample)]"
|
:rules="[rules.gt(-1)]"
|
||||||
/>
|
/>
|
||||||
|
|
||||||
<v-text-field
|
<v-text-field
|
||||||
@@ -816,30 +815,13 @@
|
|||||||
label="Sporadic Max"
|
label="Sporadic Max"
|
||||||
class="mx-3"
|
class="mx-3"
|
||||||
:disabled="sample.playbackMode != 'sporadic' || playDisabled"
|
:disabled="sample.playbackMode != 'sporadic' || playDisabled"
|
||||||
:rules="[validateSporadicRange(sample)]"
|
:rules="[rules.gt(0)]"
|
||||||
/>
|
/>
|
||||||
</v-row>
|
</v-row>
|
||||||
</v-form>
|
</v-form>
|
||||||
|
|
||||||
<v-row
|
|
||||||
justify="center"
|
|
||||||
class="my-7"
|
|
||||||
>
|
|
||||||
<p
|
|
||||||
v-if="sample.playbackMode != 'sporadic'"
|
|
||||||
class="text--disabled"
|
|
||||||
>
|
|
||||||
(Sample will play randomly, every {{ sample.sporadicMin }} to {{ sample.sporadicMax }} seconds)
|
|
||||||
</p>
|
|
||||||
<p
|
|
||||||
v-else
|
|
||||||
>
|
|
||||||
(Sample will play randomly, every {{ sample.sporadicMin }} to {{ sample.sporadicMax }} seconds)
|
|
||||||
</p>
|
|
||||||
</v-row>
|
|
||||||
|
|
||||||
<v-divider
|
<v-divider
|
||||||
class="mb-7"
|
class="mt-7"
|
||||||
/>
|
/>
|
||||||
</v-container>
|
</v-container>
|
||||||
</v-row>
|
</v-row>
|
||||||
|
|||||||
@@ -155,11 +155,13 @@ export default {
|
|||||||
this.stop()
|
this.stop()
|
||||||
},
|
},
|
||||||
methods: {
|
methods: {
|
||||||
play () {
|
async play () {
|
||||||
if (!this.players.loaded) {
|
if (!this.players.loaded) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
await Tone.start()
|
||||||
|
|
||||||
this.playDisabled = true
|
this.playDisabled = true
|
||||||
Tone.Transport.cancel()
|
Tone.Transport.cancel()
|
||||||
|
|
||||||
@@ -226,9 +228,11 @@ export default {
|
|||||||
|
|
||||||
const maxInt = parseInt(s.sporadicMax, 10)
|
const maxInt = parseInt(s.sporadicMax, 10)
|
||||||
const minInt = parseInt(s.sporadicMin, 10)
|
const minInt = parseInt(s.sporadicMin, 10)
|
||||||
const rand = Math.floor(Math.random() * (maxInt - minInt + 1) + minInt)
|
|
||||||
|
|
||||||
s.initialSporadicPlayInterval = setInterval(() => this.playSporadicSample(s.id), rand * 1000)
|
if (minInt <= maxInt) {
|
||||||
|
const rand = Math.floor(Math.random() * (maxInt - minInt + 1) + minInt)
|
||||||
|
s.initialSporadicPlayInterval = setInterval(() => this.playSporadicSample(s.id), rand * 1000)
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
this.players.player(s.id).loop = true
|
this.players.player(s.id).loop = true
|
||||||
this.players.player(s.id).unsync().sync().start(0)
|
this.players.player(s.id).unsync().sync().start(0)
|
||||||
@@ -902,15 +906,6 @@ export default {
|
|||||||
this.selectedProfile = this.profileItems.find(p => p.text === this.activeProfile.name)
|
this.selectedProfile = this.profileItems.find(p => p.text === this.activeProfile.name)
|
||||||
this.updateProfile()
|
this.updateProfile()
|
||||||
this.confirmSwitchProfileDialog = false
|
this.confirmSwitchProfileDialog = false
|
||||||
},
|
|
||||||
validateSporadicRange (sample) {
|
|
||||||
const min = parseInt(sample.sporadicMin, 10)
|
|
||||||
const max = parseInt(sample.sporadicMax, 10)
|
|
||||||
if (isNaN(min) || isNaN(max) || max <= min || min <= 0 || max <= 0) {
|
|
||||||
return 'Invalid'
|
|
||||||
} else {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user