diff options
Diffstat (limited to 'source/blender/editors/space_sequencer/sequencer_draw.c')
-rw-r--r-- | source/blender/editors/space_sequencer/sequencer_draw.c | 71 |
1 files changed, 53 insertions, 18 deletions
diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c b/source/blender/editors/space_sequencer/sequencer_draw.c index 9a904b1a970..299fe9df460 100644 --- a/source/blender/editors/space_sequencer/sequencer_draw.c +++ b/source/blender/editors/space_sequencer/sequencer_draw.c @@ -172,30 +172,63 @@ static void drawseqwave(Scene *scene, Sequence *seq, float x1, float y1, float x x2 the end x value, same for y1 and y2 stepsize is width of a pixel. */ - if(seq->sound->cache) + if(seq->flag & SEQ_AUDIO_DRAW_WAVEFORM) { - int i; + int i, j, pos; int length = floor((x2-x1)/stepsize)+1; float ymid = (y1+y2)/2; float yscale = (y2-y1)/2; - float* samples = MEM_mallocN(length * sizeof(float) * 2, "seqwave_samples"); - if(!samples) - return; - if(sound_read_sound_buffer(seq->sound, samples, length, - (seq->startofs + seq->anim_startofs)/FPS, - (seq->startofs + seq->anim_startofs + seq->enddisp - seq->startdisp)/FPS) != length) + float samplestep; + float startsample, endsample; + float value; + + SoundWaveform* waveform; + + if(!seq->sound->waveform) + sound_read_waveform(seq->sound); + + waveform = seq->sound->waveform; + + startsample = floor((seq->startofs + seq->anim_startofs)/FPS * SOUND_WAVE_SAMPLES_PER_SECOND); + endsample = ceil((seq->startofs + seq->anim_startofs + seq->enddisp - seq->startdisp)/FPS * SOUND_WAVE_SAMPLES_PER_SECOND); + samplestep = (endsample-startsample) * stepsize / (x2-x1); + + if(length > floor((waveform->length - startsample) / samplestep)) + length = floor((waveform->length - startsample) / samplestep); + + glBegin(GL_LINE_STRIP); + for(i = 0; i < length; i++) { - MEM_freeN(samples); - return; + pos = startsample + i * samplestep; + + value = waveform->data[pos * 3]; + + for(j = pos+1; (j < waveform->length) && (j < pos + samplestep); j++) + { + if(value > waveform->data[j * 3]) + value = waveform->data[j * 3]; + } + + glVertex2f(x1+i*stepsize, ymid + value * yscale); } - glBegin(GL_LINES); + glEnd(); + + glBegin(GL_LINE_STRIP); for(i = 0; i < length; i++) { - glVertex2f(x1+i*stepsize, ymid + samples[i * 2] * yscale); - glVertex2f(x1+i*stepsize, ymid + samples[i * 2 + 1] * yscale); + pos = startsample + i * samplestep; + + value = waveform->data[pos * 3 + 1]; + + for(j = pos+1; (j < waveform->length) && (j < pos + samplestep); j++) + { + if(value < waveform->data[j * 3 + 1]) + value = waveform->data[j * 3 + 1]; + } + + glVertex2f(x1+i*stepsize, ymid + value * yscale); } glEnd(); - MEM_freeN(samples); } } @@ -1042,8 +1075,8 @@ void draw_timeline_seq(const bContext *C, ARegion *ar) SpaceSeq *sseq= CTX_wm_space_seq(C); View2D *v2d= &ar->v2d; View2DScrollers *scrollers; + short unit=0, flag=0; float col[3]; - int flag=0; /* clear and setup matrix */ UI_GetThemeColor3fv(TH_BACK, col); @@ -1065,9 +1098,10 @@ void draw_timeline_seq(const bContext *C, ARegion *ar) /* draw backdrop */ draw_seq_backdrop(v2d); - /* regular grid-pattern over the rest of the view (i.e. frame grid lines) */ + /* regular grid-pattern over the rest of the view (i.e. 25-frame grid lines) */ + // NOTE: the gridlines are currently spaced every 25 frames, which is only fine for 25 fps, but maybe not for 30... UI_view2d_constant_grid_draw(v2d); - + seq_draw_sfra_efra(scene, v2d); /* sequence strips (if there is data available to be drawn) */ @@ -1110,7 +1144,8 @@ void draw_timeline_seq(const bContext *C, ARegion *ar) UI_view2d_view_restore(C); /* scrollers */ - scrollers= UI_view2d_scrollers_calc(C, v2d, V2D_UNIT_SECONDSSEQ, V2D_GRID_CLAMP, V2D_UNIT_VALUES, V2D_GRID_CLAMP); + unit= (sseq->flag & SEQ_DRAWFRAMES)? V2D_UNIT_FRAMES : V2D_UNIT_SECONDSSEQ; + scrollers= UI_view2d_scrollers_calc(C, v2d, unit, V2D_GRID_CLAMP, V2D_UNIT_VALUES, V2D_GRID_CLAMP); UI_view2d_scrollers_draw(C, v2d, scrollers); UI_view2d_scrollers_free(scrollers); } |