Commit: 9249e53f921f41a477ee325835071e0c7905364e
Author: Richard Antalik
Date:   Mon Mar 18 12:10:33 2019 -0700
Branches: master
https://developer.blender.org/rB9249e53f921f41a477ee325835071e0c7905364e

Scale waveforms & show clipping

Scale waveforms in sound strips by volume.
If any drawn line exceeds value 1 or -1 it is drawn by red color so user can 
see point, where clipping occurs.

Reviewers: brecht

Differential Revision: https://developer.blender.org/D4515

===================================================================

M       source/blender/editors/space_sequencer/sequencer_draw.c

===================================================================

diff --git a/source/blender/editors/space_sequencer/sequencer_draw.c 
b/source/blender/editors/space_sequencer/sequencer_draw.c
index 0f935031ecc..8a64b6f39db 100644
--- a/source/blender/editors/space_sequencer/sequencer_draw.c
+++ b/source/blender/editors/space_sequencer/sequencer_draw.c
@@ -191,7 +191,7 @@ void color3ubv_from_seq(Scene *curscene, Sequence *seq, 
unsigned char col[3])
 }
 
 static void drawseqwave(View2D *v2d, const bContext *C, SpaceSeq *sseq, Scene 
*scene, Sequence *seq,
-                        float x1, float y1, float x2, float y2, float 
stepsize, unsigned int pos)
+                        float x1, float y1, float x2, float y2, float stepsize)
 {
        /*
         * x1 is the starting x value to draw the wave,
@@ -257,10 +257,11 @@ static void drawseqwave(View2D *v2d, const bContext *C, 
SpaceSeq *sseq, Scene *s
                        return;
                }
 
-               immUniformColor4f(1.0f, 1.0f, 1.0f, 0.5f);
-
                GPU_blend(true);
-
+               GPUVertFormat *format = immVertexFormat();
+               uint pos = GPU_vertformat_attr_add(format, "pos", GPU_COMP_F32, 
2, GPU_FETCH_FLOAT);
+               uint col = GPU_vertformat_attr_add(format, "color", 
GPU_COMP_F32, 4, GPU_FETCH_FLOAT);
+               immBindBuiltinProgram(GPU_SHADER_2D_FLAT_COLOR);
                immBegin(GPU_PRIM_TRI_STRIP, length * 2);
 
                for (i = 0; i < length; i++) {
@@ -286,12 +287,25 @@ static void drawseqwave(View2D *v2d, const bContext *C, 
SpaceSeq *sseq, Scene *s
                                value2 = (1.0f - f) * value2 + f * 
waveform->data[p * 3 + 4];
                        }
 
+                       value1 *= seq->volume;
+                       value2 *= seq->volume;
+
+                       if (value2 > 1 || value1 < -1) {
+                               immAttr4f(col, 1.0f, 0.0f, 0.0f, 0.5f);
+
+                               CLAMP_MAX(value2, 1.0f);
+                               CLAMP_MIN(value1, -1.0f);
+                       }
+                       else {
+                               immAttr4f(col, 1.0f, 1.0f, 1.0f, 0.5f);
+                       }
+
                        immVertex2f(pos, x1_offset + i * stepsize, ymid + 
value1 * yscale);
                        immVertex2f(pos, x1_offset + i * stepsize, ymid + 
value2 * yscale);
                }
 
                immEnd();
-
+               immUnbindProgram();
                GPU_blend(false);
        }
 }
@@ -771,15 +785,15 @@ static void draw_seq_strip(
        x1 = seq->startdisp;
        x2 = seq->enddisp;
 
+       immUnbindProgram();
+
        /* draw sound wave */
        if (seq->type == SEQ_TYPE_SOUND_RAM) {
                if (!(sseq->flag & SEQ_NO_WAVEFORMS)) {
-                       drawseqwave(v2d, C, sseq, scene, seq, x1, y1, x2, y2, 
BLI_rctf_size_x(&ar->v2d.cur) / ar->winx, pos);
+                       drawseqwave(v2d, C, sseq, scene, seq, x1, y1, x2, y2, 
BLI_rctf_size_x(&ar->v2d.cur) / ar->winx);
                }
        }
 
-       immUnbindProgram();
-
        /* draw lock */
        if (seq->flag & SEQ_LOCK) {
                GPU_blend(true);

_______________________________________________
Bf-blender-cvs mailing list
Bf-blender-cvs@blender.org
https://lists.blender.org/mailman/listinfo/bf-blender-cvs

Reply via email to