Skip to content

Commit

Permalink
--wip--
Browse files Browse the repository at this point in the history
  • Loading branch information
wolfbiter committed Aug 14, 2016
1 parent a752567 commit 6c42fe3
Show file tree
Hide file tree
Showing 9 changed files with 97 additions and 31 deletions.
1 change: 1 addition & 0 deletions app/components/arrangement-visual/track-clip.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export default Clip.extend(
audioMeta: Ember.computed.reads('track.audioMeta'),
trackBpm: Ember.computed.reads('audioMeta.bpm'),
trackBeatCount: Ember.computed.reads('audioMeta.beatCount'),
trackBarCount: Ember.computed.reads('audioMeta.barCount'),
trackDuration: Ember.computed.reads('audioMeta.duration'),
audioBinary: Ember.computed.reads('track.audioBinary'),
audioBuffer: Ember.computed.reads('audioBinary.audioBuffer'),
Expand Down
12 changes: 11 additions & 1 deletion app/components/arrangement-visual/track-clip/wave.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { join } from 'ember-cli-d3/utils/d3';
import multiply from 'linx/lib/computed/multiply';

export default Ember.Component.extend(
GraphicSupport('peaks.[]', 'waveColor', 'height'), {
GraphicSupport('peaks.[]', 'waveColor', 'height', 'trackBarCount', 'pxPerBeat', 'startBar'), {

// required params
peaks: null,
Expand All @@ -17,6 +17,16 @@ export default Ember.Component.extend(
height: 125,
waveColor: 'green',

minX: 0,
maxX: multiply('trackBeatCount', 'pxPerBeat'),

barScale: Ember.computed('startBar', 'trackBarCount', 'minX', 'maxX', function () {
const domainMin = this.get('startBar');
const domainMax = this.get('trackBarCount');

return d3.scale.linear().domain([domainMin, domainMax]).range([this.get('minX'), this.get('maxX')]);
}).readOnly(),

call(selection) {
this._super.apply(this, arguments);

Expand Down
15 changes: 2 additions & 13 deletions app/components/mix-builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -318,18 +318,6 @@ export default Ember.Component.extend(
this.send('addTrack', track);
});
},

// appendRandomTrack() {
// const mix = this.get('mix');
// const tracks = this.get('searchTracks.content');
// const randomTrack = _.sample(tracks.toArray());

// mix.appendTrack(randomTrack);
// },

// toggleShowVolumeAutomation() {
// this.toggleProperty('showVolumeAutomation');
// },
},

// TODO(TECHDEBT): make this work with query param for sleected transition?
Expand All @@ -350,10 +338,11 @@ export default Ember.Component.extend(

// get default quantization
// TODO(TECHDEBT): does this make sense to always say? how to tell if this event is active?
let defaultQuantization = this.get('selectedQuantization');
const defaultQuantization = this.get('selectedQuantization');
const isAltKeyHeld = Ember.get(d3, 'event.sourceEvent.altKey') || Ember.get(d3, 'event.altKey');
const isCtrlKeyHeld = Ember.get(d3, 'event.sourceEvent.ctrlKey') || Ember.get(d3, 'event.ctrlKey') ||
Ember.get(d3, 'event.sourceEvent.metaKey') || Ember.get(d3, 'event.metaKey');

if (isAltKeyHeld) {
quantization = SAMPLE_QUANTIZATION;
} else if (isCtrlKeyHeld) {
Expand Down
24 changes: 23 additions & 1 deletion app/components/mix-builder/precision-controls/track.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default Ember.Component.extend({
jumpTrack: Ember.K,
quantizeBeat: Ember.K,

// internal params
track: Ember.computed.reads('clip.track'),

actions: {
Expand All @@ -28,7 +29,28 @@ export default Ember.Component.extend({
audioStartTime: time,
});
});
}
},

resetDownbeat() {
const clip = this.get('clip.content') || this.get('clip');

const prevStartTime = clip.get('audioStartTime');
const beatGrid = this.get('track.audioMeta.beatGrid');
const newStartTime = beatGrid.timeToQuantizedDownbeatTime(prevStartTime);

console.log("QUANTIZE OLD", beatGrid.timeToBar(prevStartTime))
console.log("QUANTIZE NEW", newStartTime)

clip.setProperties({
audioStartTime: newStartTime,
});
},

setDownbeat() {
const audioMeta = this.get('track.audioMeta.content');

audioMeta.set('barGridTime', this.get('clip.audioStartTime'));
},
}
});

13 changes: 6 additions & 7 deletions app/models/track/audio-meta.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ export default DS.Model.extend(
bpm: DS.attr('number'),
timeSignature: DS.attr('number', { defaultValue: 4 }),
key: DS.attr('number'),
keyText: DS.attr('string'), // TODO(TECHDEBT)
keyText: DS.attr('string'), // TODO(TECHDEBT): dedupe with key, mode fields
mode: DS.attr('number'),
loudness: DS.attr('number'),
barGridTime: DS.attr('number', { defaultValue: 0 }),
Expand All @@ -120,6 +120,7 @@ export default DS.Model.extend(
this.set('barGridTime', this.get('barGridTime') + value);
},

// TODO(TECHDEBT)
// // calculate gain from loudness (decibels)
// gain: Ember.computed('loudness', {
// get() {
Expand Down Expand Up @@ -176,17 +177,15 @@ export default DS.Model.extend(
}),
centerBeat: add('startBeat', 'halfBeatCount'),

barCount: Ember.computed('beatCount', 'timeSignature', function() {
return this.get('beatCount') / this.get('timeSignature');
}),

firstWholeBeat: 0,
firstWholeBar: 0,
lastWholeBeat: computedBarToBeat('beatGrid', 'lastWholeBar'),
lastWholeBar: computedQuantizeBar('beatGrid', 'endBar'),

// TODO: implement this, and move to audio-meta/beat-grid?
// amount by which echonest analysis is off from the downbeats
// calculated by diff from echonest section markers and the grid marker
echonestBeatOffset: Ember.computed('beatGrid.beatScale', 'beatGrid.barScale', function() {
}),

destroyMarkers: function() {
return this.get('markers').then((markers) => {
return Ember.RSVP.all(markers.map((marker) => {
Expand Down
12 changes: 11 additions & 1 deletion app/models/track/audio-meta/beat-grid.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,10 @@ export default Ember.Object.extend({
return this.quantizeBar(this.timeToBar(time));
},

timeToQuantizedDownbeatTime(time) {
return this.barToTime(this.timeToQuantizedBar(time));
},

// Beat Scale
// domain is time [s]
// range is beats [b]
Expand All @@ -90,6 +94,7 @@ export default Ember.Object.extend({
quantizeBeatScaleRange: Ember.computed('beatScaleRange', function() {
let beatScale = this.get('beatScale');
let [rangeMin, rangeMax] = beatScale.get('range');
// TODO: i think below line is deprecated, and can be removed?
// return d3.range(Math.ceil(rangeMin), Math.floor(rangeMax), 1);
return [Math.ceil(rangeMin), Math.floor(rangeMax)];
}),
Expand Down Expand Up @@ -128,22 +133,27 @@ export default Ember.Object.extend({
return timeToBeat(this.get('duration'), this.get('bpm'));
}),

// the time of the first actual beat in the raw audio file
// the time of the first actual downbeat in the raw audio file
// TODO(MULTIGRID): this supposes a constant bpm in the audio file
firstBarOffset: Ember.computed('barGridTime', 'bpm', 'timeSignature', function() {
const bpm = this.get('bpm');
const timeSignature = this.get('timeSignature');
const secondsPerBeat = bpmToSpb(bpm);
const secondsPerBar = secondsPerBeat * timeSignature;

console.log('calculating firstBarOffset')

let firstBarOffsetTime = this.get('barGridTime');
console.log('barGridTime', firstBarOffsetTime)
if (isValidNumber(bpm) && isValidNumber(timeSignature) && isValidNumber(firstBarOffsetTime)) {
while ((firstBarOffsetTime - secondsPerBar) >= 0) {
firstBarOffsetTime -= secondsPerBar;
}

console.log('firstBarOffsetTime', firstBarOffsetTime)
return firstBarOffsetTime * secondsPerBar;
} else {
console.log('no firstBarOffsetTime', 0)
return 0;
}
}),
Expand Down
28 changes: 28 additions & 0 deletions app/styles/components/_arrangement-visual/track-clip.scss
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,31 @@
.ArrangementVisualTrackClip-startOverlay, .ArrangementVisualTrackClip-endOverlay {
fill: rgba(#000, 0.5);
}

.ArrangementVisualTrackClip-beatAxis, .ArrangementVisualTrackClip-barAxis {
height: 30px;
color: white;
stroke: white;

text {
display: none;
}

.data-visual {
width: 100%;
height: 100%;
}

.tick line {
stroke-width: 1;
stroke: rgba(#f0f, 0.8);
}

.domain {
fill: none;
}
}

.ArrangementVisualTrackClip-barAxis {
stroke: rgba(#fff, 0.3);
}
14 changes: 6 additions & 8 deletions app/templates/components/arrangement-visual/track-clip.hbs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
{{!-- {{arrangement-visual/track-clip/axis
select=select
clip=clip
pxPerBeat=pxPerBeat
}}
--}}

{{arrangement-visual/track-clip/wave
select=select.TrackClip-wave
isD3Visible=displayWaveform
waveColor=waveColor
transform=(if displayOverflowWaveform startOffsetTransform)
transform=startOffsetTransform
startBar=audioMeta.startBar
trackBarCount=trackBarCount
trackBeatCount=trackBeatCount
pxPerBeat=pxPerBeat
peaks=trackPeaks
height=height
}}
{{!-- transform=(if displayOverflowWaveform startOffsetTransform) --}}
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
{{d3-axis
select=select.ArrangementVisualTrackClip-barAxis
transform=(svg-translate 0 height)
scale=barScale
orient="top"
ticks=trackBarCount
tickSize=height
}}

{{yield}}

0 comments on commit 6c42fe3

Please sign in to comment.