diff --git a/server/boot/db.js b/server/boot/db.js
index 7fe5e78..9a2b186 100644
--- a/server/boot/db.js
+++ b/server/boot/db.js
@@ -1,4 +1,5 @@
const db = require('../db')
+const logger = require('../logger')
module.exports = function () {
db.serialize(() => {
@@ -51,5 +52,23 @@ module.exports = function () {
FOREIGN KEY(profile) REFERENCES profiles(id),
FOREIGN KEY(sample) REFERENCES samples(id))`
)
+
+ db.get('PRAGMA user_version', (err, row) => {
+ if (err) {
+ logger.error(err)
+ } else {
+ const userVersion = row.user_version
+
+ if (userVersion === 0) {
+ db.run('ALTER TABLE samples ADD COLUMN fade_in REAL DEFAULT 0')
+ db.run('ALTER TABLE samples ADD COLUMN fade_out REAL DEFAULT 0')
+ db.run('ALTER TABLE samples ADD COLUMN loop_points_enabled INTEGER 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')
+ }
+ }
+ })
})
}
diff --git a/server/routes/samples.js b/server/routes/samples.js
index f9d422a..c3a69cb 100644
--- a/server/routes/samples.js
+++ b/server/routes/samples.js
@@ -77,7 +77,15 @@ router.get('/samples', (req, res) => {
const samples = []
- db.all('SELECT id, name FROM samples WHERE user = ?', [req.user.id], (err, rows) => {
+ db.all(`SELECT
+ id,
+ name,
+ fade_in as fadeIn,
+ fade_out as fadeOut,
+ loop_points_enabled as loopPointsEnabled,
+ loop_start as loopStart,
+ loop_end as loopEnd
+ FROM samples WHERE user = ?`, [req.user.id], (err, rows) => {
if (err) {
logger.error(err)
return res.sendStatus(500)
@@ -88,6 +96,11 @@ router.get('/samples', (req, res) => {
sample.id = row.id
sample.name = row.name
+ sample.fadeIn = row.fadeIn
+ sample.fadeOut = row.fadeOut
+ sample.loopPointsEnabled = row.loopPointsEnabled === 1
+ sample.loopStart = row.loopStart
+ sample.loopEnd = row.loopEnd
sample.user = req.user.id
samples.push(sample)
@@ -97,4 +110,38 @@ router.get('/samples', (req, res) => {
})
})
+router.get('/samples/:sampleId', (req, res) => {
+ if (!req.user) {
+ return res.sendStatus(401)
+ }
+
+ db.get(`SELECT
+ id,
+ name,
+ fade_in as fadeIn,
+ fade_out as fadeOut,
+ loop_points_enabled as loopPointsEnabled,
+ loop_start as loopStart,
+ loop_end as loopEnd
+ FROM samples WHERE user = ? AND id = ?`, [req.user.id, req.params.sampleId], (err, row) => {
+ if (err) {
+ logger.error(err)
+ return res.sendStatus(500)
+ }
+
+ const sample = {}
+
+ sample.id = row.id
+ sample.name = row.name
+ sample.fadeIn = row.fadeIn
+ sample.fadeOut = row.fadeOut
+ sample.loopPointsEnabled = row.loopPointsEnabled === 1
+ sample.loopStart = row.loopStart
+ sample.loopEnd = row.loopEnd
+ sample.user = req.user.id
+
+ res.json({ sample: sample })
+ })
+})
+
module.exports = router
diff --git a/src/components/Noise.vue b/src/components/Noise.vue
index b18bcf5..497dbac 100644
--- a/src/components/Noise.vue
+++ b/src/components/Noise.vue
@@ -680,6 +680,101 @@
+
+
+
+
+ Edit Samples
+
+
+
+
+
+ Edit Sample
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Preview Sample
+
+
+
+
+
+
+
+ Cancel
+
+
+ Edit
+
+
+
+
+
{
+ this.players.player(s.id).loop = true
+ this.players.player(s.id).fadeIn = s.fadeIn
+ this.players.player(s.id).fadeOut = s.fadeOut
+ if (s.loopPointEnabled) {
+ this.players.player(s.id).setLoopPoints(s.loopStart, s.loopEnd)
+ }
+ })
+
if (this.isTimerEnabled) {
this.duration = parseInt((this.hours * 3600)) + parseInt((this.minutes * 60)) + parseInt(this.seconds)
this.noise.sync().start(0).stop(this.duration)
@@ -126,14 +145,12 @@ export default {
this.timeRemainingInterval = setInterval(() => this.startTimer(), 1000)
this.loadedSamples.forEach(s => {
- this.players.player(s.id).loop = true
this.players.player(s.id).unsync().sync().start(0).stop(this.duration)
})
} else {
this.noise.sync().start(0)
this.loadedSamples.forEach(s => {
- this.players.player(s.id).loop = true
this.players.player(s.id).unsync().sync().start(0)
})
}
@@ -225,6 +242,17 @@ export default {
}
})
},
+ populateSampleItems () {
+ this.$http.get('/samples')
+ .then(response => {
+ if (response.status === 200) {
+ this.sampleItems = response.data.samples
+ if (this.sampleItems.length > 0) {
+ this.selectedEditSample = this.sampleItems[0]
+ }
+ }
+ })
+ },
addDefaultProfile () {
this.$http.post('/profiles/default')
.then(response => {
@@ -364,6 +392,7 @@ export default {
.then(response => {
if (response.status === 200) {
this.getSamples()
+ this.populateSampleItems()
this.infoSnackbarText = 'Sample Uploaded'
this.infoSnackbar = true
}
@@ -415,6 +444,11 @@ export default {
this.$refs.uploadSampleForm.reset()
}
},
+ resetEditSampleForm () {
+ if (this.$refs.editSampleForm) {
+ this.$refs.editSampleForm.reset()
+ }
+ },
openImportDialog () {
this.profileMoreDialog = false
this.importDialog = true
@@ -510,6 +544,29 @@ export default {
})
this.exportDialog = false
+ },
+ previewSample () {
+ this.samplePreviewPlayer.toDestination()
+
+ if (this.samplePreviewPlaying) {
+ this.samplePreviewPlayer.stop()
+ this.samplePreviewPlaying = false
+ } else {
+ this.$http.get('/samples/'.concat(this.selectedEditSample.id))
+ .then(async response => {
+ if (response.status === 200) {
+ const sample = response.data.sample
+
+ await this.samplePreviewPlayer.load('/samples/' + sample.user + '_' + sample.name)
+ this.samplePreviewPlayer.loop = true
+ this.samplePreviewPlayer.start()
+
+ this.samplePreviewPlaying = true
+ }
+ })
+ }
+ },
+ editSample () {
}
}
}