Skip to content

Commit 08c2905

Browse files
committed
Added playback of selection only.
1 parent 299f414 commit 08c2905

5 files changed

+31
-9
lines changed

css/app.css

+8
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,11 @@ body { background-color: #FFFFFF; }
77
#toolbar { float: left; }
88

99
canvas { display: none; }
10+
11+
.fa-sub {
12+
position: relative;
13+
left: -.6em;
14+
width: .2em;
15+
vertical-align: -.25em;
16+
text-shadow: 0 0 1px black;
17+
}

index.html

+11-5
Original file line numberDiff line numberDiff line change
@@ -34,20 +34,26 @@
3434
<i class="fa fa-fw fa-arrows"></i>
3535
</div>
3636
</label>
37-
<label class="btn btn-primary" ng-model="opModel" btn-radio="'scaleh'">
37+
<label class="btn btn-primary" ng-model="opModel" btn-radio="'scaleh'" disabled="true">
3838
<div tooltip-placement="right" tooltip="Scale selection horizontally">
3939
<i class="fa fa-fw fa-arrows-h"></i>
4040
</div>
4141
</label>
42-
<label class="btn btn-primary" ng-model="opModel" btn-radio="'scalev'">
42+
<label class="btn btn-primary" ng-model="opModel" btn-radio="'scalev'" disabled="true">
4343
<div tooltip-placement="right" tooltip="Scale selection vertically">
4444
<i class="fa fa-fw fa-arrows-v"></i>
4545
</div>
4646
</label>
4747
</div>
48-
<button ng-class="{'btn':true, 'btn-success':!isPlaying, 'btn-danger':isPlaying}" tooltip="Play" playback>
49-
<i ng-class="{'fa':true, 'fa-play':!isPlaying, 'fa-stop':isPlaying}"></i>
50-
</button>
48+
<div class="btn-group">
49+
<button ng-class="{'btn':true, 'btn-success':!isPlaying, 'btn-danger':isPlaying}" tooltip="Play" tooltip-placement="bottom" playback>
50+
<i ng-class="{'fa fa-lg':true, 'fa-play':!isPlaying, 'fa-stop':isPlaying}"></i>
51+
</button>
52+
<button ng-class="{'btn':true, 'btn-success':!isPlaying, 'btn-danger':isPlaying}" tooltip="Play selection" tooltip-placement="bottom" playback data-use-selection="true">
53+
<i ng-class="{'fa fa-lg ':true, 'fa-play':!isPlaying, 'fa-stop':isPlaying}"></i>
54+
<i class="fa fa-edit fa-sub"></i>
55+
</button>
56+
</div>
5157
<div sound-magic>
5258
<svg partial-plot>
5359
</svg>

js/PartialPlotDirective.js

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
app.directive('partialPlot', function($window) {
22
return function(scope, element, attrs) {
33

4+
var svg;
5+
46
var isPartialSelected = function(partial, box) {
57
// Check if one of the points lies in the selection box
68
return _(partial)
@@ -18,7 +20,7 @@ app.directive('partialPlot', function($window) {
1820
var w = 960 - margin.left - margin.right;
1921
var h = 500 - margin.top - margin.bottom;
2022

21-
var svg = d3.select(canvas)
23+
svg = d3.select(canvas)
2224
.attr('width', w + margin.left + margin.right)
2325
.attr('height', h + margin.top + margin.bottom)
2426
.append('g')
@@ -173,5 +175,9 @@ app.directive('partialPlot', function($window) {
173175
var spectrogram = scope.spectrogram;
174176
plotPartials(element[0], partials, sampleRate, spectrogram);
175177
};
178+
179+
scope.getSelection = function() {
180+
return svg.selectAll('.selected').data();
181+
};
176182
};
177183
});

js/PlaybackDirective.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
app.directive('playback', function($window) {
22
return function(scope, element, attrs) {
33
var btn = element[0];
4+
var useSelection = attrs.useSelection || false;
45

56
scope.isPlaying = false;
67

@@ -15,7 +16,8 @@ app.directive('playback', function($window) {
1516
};
1617

1718
var startPlayback = function() {
18-
var buffer = scope.synthesize();
19+
var partials = useSelection ? scope.getSelection() : scope.partials;
20+
var buffer = scope.synthesize(partials);
1921

2022
var len = buffer.length;
2123
var webAudioBuf = scope.audioContext.createBuffer(1, len, scope.sampleRate);

js/SoundMagicDirective.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -118,8 +118,8 @@ app.directive('soundMagic', function($window) {
118118

119119
// Create playback parameters
120120
scope.sampleRate = sampleRate;
121-
scope.synthesize = function() {
122-
return mqAudio.synthesize(scope.partials, fftsize, sampleRate);
121+
scope.synthesize = function(partials) {
122+
return mqAudio.synthesize(partials, fftsize, sampleRate);
123123
};
124124

125125
if (processedCallback) {

0 commit comments

Comments
 (0)