Comparing version 0.0.4 to 0.0.5
26
album.js
@@ -6,2 +6,3 @@ const Batch = require('batch') | ||
const path = require('path') | ||
const { Master, Premaster } = require('./master') | ||
const { Pool } = require('nanoresource-pool') | ||
@@ -18,3 +19,16 @@ const Track = require('./track') | ||
.filter(f => path.extname(f) === '.wav') | ||
this.infoTags = [] | ||
if (opts.metadata) { | ||
if (opts.metadata.artist) { | ||
this.infoTags.push(['IART', opts.metadata.artist]) | ||
} | ||
if (opts.metadata.comment) { | ||
this.infoTags.push(['ICMT'], opts.metadata.comment) | ||
} | ||
if (opts.metadata.album) { | ||
this.infoTags.push(['IPRD', opts.metadata.album]) | ||
} | ||
} | ||
let counter = 0 | ||
@@ -24,8 +38,7 @@ for (const source of this.sources) { | ||
debug('track counter', counter) | ||
this.add(new Track(source, { trackNumber: counter })) | ||
this.add(new Premaster(source, { | ||
trackNumber: counter, | ||
tags: this.infoTags | ||
})) | ||
} | ||
if (opts.metadata) { | ||
this.metadata = opts.metadata | ||
} | ||
} | ||
@@ -72,4 +85,3 @@ | ||
}, | ||
silences: this.query().every(tr => tr.silences.start && tr.silences.end), | ||
stats: this.query().every(tr => tr.stats.peak.valid && tr.stats.rms.valid) | ||
silences: this.query().every(tr => tr.silences.start && tr.silences.end) | ||
} | ||
@@ -76,0 +88,0 @@ |
21
asset.js
const debug = require('debug')('baptism:track') | ||
const fs = require('fs') | ||
const mime = require('mime') | ||
const path = require('path') | ||
const Resource = require('nanoresource') | ||
@@ -9,5 +10,15 @@ | ||
super() | ||
this.filename = source | ||
this.hint = '' | ||
this.filename = path.resolve(source) | ||
this.type = mime.getType(this.filename) | ||
this.fd = 0 | ||
if (opts.hint) { | ||
this.hint = opts.hint | ||
} | ||
if (this.type.includes('image') || this.hint === 'image') { | ||
this.binary = Buffer.from(fs.readFileSync(this.filename)) | ||
.toString('base64') | ||
} | ||
} | ||
@@ -30,2 +41,8 @@ | ||
module.exports = Asset | ||
class CoverArt extends Asset { | ||
constructor(source, opts={}) { | ||
super(source, Object.assign({ hint: 'coverart' }, opts)) | ||
} | ||
} | ||
module.exports = { Asset, CoverArt } |
@@ -7,2 +7,8 @@ const bap = require('../index') | ||
console.log(res) | ||
newAlbum.query()[0].spectrogram((err, spec) => { | ||
console.log(`Spectrogram output to: ${spec}`) | ||
newAlbum.query()[0].waveform((err, wave) => { | ||
console.log(`Waveform output to: ${wave}`) | ||
}) | ||
}) | ||
}) |
const Album = require('./album') | ||
const { Asset, CoverArt } = require('./asset') | ||
const { Master, Premaster } = require('./master') | ||
const Release = require('./release') | ||
@@ -13,3 +15,3 @@ const Track = require('./track') | ||
module.exports = { | ||
Album, Release, Track, flags, soxi, stats, spectrogram | ||
Album, Asset, CoverArt, Master, Premaster, Release, Track, flags, soxi, stats, spectrogram | ||
} |
{ | ||
"name": "baptism", | ||
"version": "0.0.4", | ||
"version": "0.0.5", | ||
"description": "", | ||
@@ -18,4 +18,5 @@ "main": "index.js", | ||
"nanoresource": "^1.3.0", | ||
"nanoresource-pool": "^0.3.1" | ||
"nanoresource-pool": "^0.3.1", | ||
"wavefile": "^11.0.0" | ||
} | ||
} |
@@ -33,2 +33,8 @@ # SACRED1: Baptism | ||
console.log(res) | ||
newAlbum.query()[0].spectrogram((err, spec) => { | ||
console.log(`Spectrogram output to: ${spec}`) | ||
newAlbum.query()[0].waveform((err, wave) => { | ||
console.log(`Waveform output to: ${wave}`) | ||
}) | ||
}) | ||
}) | ||
@@ -39,3 +45,3 @@ ``` | ||
{ | ||
'/home/agrathwohl/code/sacreddata/baptism/example/example.wav': { | ||
'/home/gwohl/code/sacreddata/baptism/example/example.wav': { | ||
duration: 10, | ||
@@ -46,2 +52,4 @@ peak: { db: -0.018041945998171376, value: 0.997925, valid: false }, | ||
} | ||
Spectrogram output to: /home/gwohl/code/sacreddata/baptism/example/example.wav.png | ||
Waveform output to: /home/gwohl/code/sacreddata/baptism/example/example.wav_waveform.png | ||
``` | ||
@@ -56,3 +64,3 @@ | ||
### `const album = new bap.Album(dir)` | ||
### `const album = new bap.Album(dir, [opts])` | ||
@@ -62,2 +70,9 @@ An object, which provides one or more `Track` objects. Extends | ||
The optional `opts` object allows for designating the following flags: | ||
`opts.metadata`: An object to specify metadata about the `Album`. Accepted keys | ||
are `opts.metadata.artist`, `opts.metadata.album`, `opts.metadata.title`, and | ||
`opts.metadata.comment`. This metadata will be written to any WAVs output from | ||
the `Album` object. | ||
#### `album.probe(callback)` | ||
@@ -74,8 +89,12 @@ | ||
### `const asset = new bap.Asset(file)` | ||
### `const asset = new bap.Asset(file, [opts])` | ||
An object, which represents and objectifies a single `Asset` meant to be added | ||
to an `Album` prior to completion. Extends | ||
[`nanoresource`](https://github.com/little-core-labs/nanoresource). | ||
to an `Album` prior to completion. Accepts an optional `opts` object, with the | ||
following keys: | ||
`opts.hint`: A string that provides an indication of the function of the asset. | ||
Extends [`nanoresource`](https://github.com/mafintosh/nanoresource). | ||
### `const flags = bap.flags` | ||
@@ -103,2 +122,22 @@ | ||
### `const master = bap.Master(filename, [opts])` | ||
An object representing a mastered music track. Extends `bap.Track`. Accepts an | ||
optional `opts` object with the following configuration parameters: | ||
`opts.parent`: Specify the `Track` object which served as the premaster source | ||
file for this `Master`. This property can also be set later via | ||
`bap.Master.parent`. | ||
#### `master.compare(callback)` | ||
Compare the `Master` audio file's dynamics and formatting properties with its | ||
parent `Track`. Performs necessary analyses on the `Master` and `Track` objects | ||
if the information is not already available. Callback returns an object which | ||
provides comparison results and validations validations. | ||
### `const premaster = bap.Premaster(filename, [opts])` | ||
> WIP | ||
### `const Release = bap.Release` | ||
@@ -135,4 +174,4 @@ | ||
An object, which represents a single audio file. Extends | ||
[nanoresource](https://github.com/little-core-labs/nanoresource). Accepts an | ||
optional options object to specify track number, via `opts.trackNumber`. | ||
[nanoresource](https://github.com/mafintosh/nanoresource). Accepts an optional | ||
`opts` object to specify track number, via `opts.trackNumber`. | ||
@@ -165,2 +204,9 @@ #### `track.size(callback)` | ||
#### `track.wav` | ||
When `Track.source` points to a WAV file, `track.wav` will be provided upon | ||
instantiation, giving full access to the file via the | ||
[`WaveFile`](https://github.com/rochars/wavefile) npm module. This allows users | ||
to set/remove RIFF tags, parse WAV chunks, modify WAV formatting, etc. | ||
#### `track.waveform(callback)` | ||
@@ -167,0 +213,0 @@ |
const Album = require('./album') | ||
const Asset = require('./asset') | ||
const { Asset } = require('./asset') | ||
const Track = require('./track') | ||
@@ -25,4 +25,8 @@ | ||
} else { | ||
throw new Error('Must be an Album or a Track') | ||
throw new Error('Must be an Album, Track, or Asset object') | ||
} | ||
if (this.minutesPerSide) { | ||
this.sides = Number((this.duration / (this.minutesPerSide * 60 * 2)).toFixed(0.1)) + 1 | ||
} | ||
} | ||
@@ -34,2 +38,6 @@ } | ||
super(opts) | ||
/* | ||
* TODO @agrathwohl | ||
* Provide a CUE sheet file path as an option for the constructor | ||
*/ | ||
} | ||
@@ -44,2 +52,14 @@ } | ||
class Download extends Digital { | ||
constructor(opts={}) { | ||
super(opts) | ||
} | ||
} | ||
class Stream extends Digital { | ||
constructor(opts={}) { | ||
super(opts) | ||
} | ||
} | ||
class Vinyl extends Release { | ||
@@ -93,3 +113,3 @@ constructor(opts={}) { | ||
module.exports = { | ||
CD, Digital, Release, Vinyl | ||
CD, Digital, Download, Release, Stream, Vinyl | ||
} |
@@ -11,9 +11,7 @@ const debug = require('debug')('baptism:stats') | ||
db: 20 * Math.log10( stats[3] ), | ||
value: stats[3], | ||
valid: stats[3] <= 0.7 // -3dBFS | ||
value: stats[3] | ||
}, | ||
rms: { | ||
db: 20 * Math.log10( stats[8] ), | ||
value: stats[8], | ||
valid: stats[8] <= 0.25 && stats[8] >= 0.03 // low: -30dB; high: -12dB | ||
value: stats[8] | ||
} | ||
@@ -20,0 +18,0 @@ } |
32
track.js
@@ -0,1 +1,2 @@ | ||
const { Asset } = require('./asset') | ||
const debug = require('debug')('baptism:track') | ||
@@ -10,3 +11,5 @@ const flags = require('./flags.json') | ||
const Resource = require('nanoresource') | ||
const WaveFile = require('wavefile').WaveFile | ||
class Track extends Resource { | ||
@@ -19,5 +22,22 @@ constructor(source, opts = {}) { | ||
if (opts.tags) { | ||
this.tags = opts.tags | ||
} | ||
if (opts.trackNumber) { | ||
this.trackNumber = opts.trackNumber | ||
} | ||
if (this.type === 'audio/wav') { | ||
this.wav = new WaveFile() | ||
this.wav.fromBase64(Buffer.from(fs.readFileSync(this.filename)) | ||
.toString('base64')) | ||
if (this.tags) { | ||
for (const tag of this.tags) { | ||
this.wav.setTag(...tag) | ||
} | ||
} | ||
} | ||
} | ||
@@ -115,6 +135,4 @@ | ||
if (err) return cb(err) | ||
this.spectrogramFile = sp | ||
this.spectrogram = Buffer.from(fs.readFileSync(this.spectrogramFile)) | ||
.toString('base64') | ||
this.inactive(cb, null, sp) | ||
this.spectrogram = new Asset(sp, { hint: 'image' }) | ||
this.inactive(cb, null, this.spectrogram) | ||
}) | ||
@@ -149,6 +167,4 @@ }) | ||
debug('waveform finished', waveformPath) | ||
this.waveformFile = waveformPath | ||
this.waveform = Buffer.from(fs.readFileSync(this.waveformFile)) | ||
.toString('base64') | ||
this.inactive(cb, null, waveformPath) | ||
this.waveform = new Asset(waveformPath, { hint: 'image' }) | ||
this.inactive(cb, null, this.waveform) | ||
}) | ||
@@ -155,0 +171,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
2206347
17
499
209
8
+ Addedwavefile@^11.0.0
+ Addedwavefile@11.0.0(transitive)