Re: [CinCV] A plugin that can add labels to the EDL?

Top Page
Attachments:
Message as email
+ (text/plain)
+ cinelerra.diff (text/x-patch)
Delete this message
Reply to this message
Author: percy tiglao
Date:  
To: cinelerra
Subject: Re: [CinCV] A plugin that can add labels to the EDL?
On 7/2/08, Johannes Sixt <johannes.sixt@???> wrote:
> On Mittwoch, 2. Juli 2008, percy tiglao wrote:
>> The "spectrometer" plugin looks extremely useful... but not in its
>> current state. So I'm doing a few touchups on the plugin right now to
>> fit my needs. One particular feature that I'd really like is to add
>> "labels" by clicking on points on the spectrometer's GUI. This way I
>> can see key events on the spectrometer and break them down. (IE:
>> separate drum beats from bells and what not)
>>
>> Question1: Are there any plugins/effects that offer this functionality
>> (the ability to add labels) already?
>> Question2: How exactly do labels work from a coding perspective? I see
>> some references in the EDL object, but if someone gave me a starting
>> point to look that would be great.
>
> If I understand you correctly, then the labels that you want to add to the
> spectrometer have nothing to do with the labels on the timeline.


I mean I'd like them actually on the timeline. Sorry for being
unclear. I would like
to be able to select an arbitrary spot in the Spectrometer window, and
somehow place
a label on the time that correlates to the selected spot in the spectrometer.

> I suggest that you introduce keyframes in the plugin if it doesn't have
> them,
> yet. Then you store the label information in the keyframe data. You can look
> into other effects how the keyframe infrastructure works: You add a class
> with these functions (see plugins/titler/title.[Ch]):
>
>     int equivalent(TitleConfig &that);
>     void copy_from(TitleConfig &that);
>     void interpolate(TitleConfig &prev,
>         TitleConfig &next,
>         int64_t prev_frame,
>         int64_t next_frame,
>         int64_t current_frame);
>
> (interplate() need not necessarily do interpolation if it does not make
> sense.)


Hmm, labels from keyframe data also seem useful if I am unable to edit the
EDL labels directly.

>> Question3: When I'm done, who/where should I submit the patch?
>
> Post it here.


I've got an early version that is working a lot better than the old
spectrometer already, so I thought I should submit the attached patch.
My next milestone is to add BC_FPot
to control the "WINDOW_SIZE" and "STEP", so that you don't have to recompile the
plugin to change these key parameters.

Here's a screenshot of how this updated Spectrometer looks like:
http://img244.imageshack.us/my.php?image=spectromi3.png

For some reason, a ton of unnecessary information was generated when I
ran the "svn diff" command in the main directory... so I just ran svn
diff in the plugins/spectrogram directory.

--Percival
Index: spectrogram.C
===================================================================
--- spectrogram.C    (revision 1060)
+++ spectrogram.C    (working copy)
@@ -15,10 +15,19 @@

REGISTER_PLUGIN(Spectrogram)

+// 16384 is a decent value
+// Smaller values are more accurate with time, while larger values
+// offer more accuracy in frequency. This should be easily set by the user
+// eventually...
#define WINDOW_SIZE 4096
-#define HALF_WINDOW 2048
+#define HALF_WINDOW (WINDOW_SIZE/2)

+// Step can be seen as how zoomed in the spectrometer is. The higher the
+// step size, the more zoomed in on the x-axis the GUI will be. An unfortunate
+// side effect is that large values of STEP slow down the playback.
+#define STEP 8

+
SpectrogramConfig::SpectrogramConfig()
{
    level = 0.0;
@@ -31,7 +40,7 @@


SpectrogramLevel::SpectrogramLevel(Spectrogram *plugin, int x, int y)
- : BC_FPot(x, y, plugin->config.level, INFINITYGAIN, 0)
+ : BC_FPot(x, y, plugin->config.level, -100, 0)
{
    this->plugin = plugin;
}
@@ -75,7 +84,7 @@
void SpectrogramWindow::create_objects()
{
    int x = 60, y = 10;
-    int divisions = 5;
+    int divisions = 20;
    char string[BCTEXTLEN];

    add_subwindow(canvas = new BC_SubWindow(x,
@@ -175,7 +184,7 @@


Spectrogram::Spectrogram(PluginServer *server)
- : PluginAClient(server)
+ : PluginAClient(server), column(0), background(0)
{
    reset();
    PLUGIN_CONSTRUCTOR_MACRO
@@ -218,16 +227,26 @@
        data = new float[HALF_WINDOW];
    }

-    bzero(data, sizeof(float) * HALF_WINDOW);
-    total_windows = 0;
-    fft->process_buffer(start_position,
-        size,
-        buffer,
-        get_direction());
-    for(int i = 0; i < HALF_WINDOW; i++)
-        data[i] /= total_windows;
-    send_render_gui(data, HALF_WINDOW);
+    read_samples(buffer, 0, sample_rate, start_position, size);
+    double* copy = new double[size];
+    int inc = (size/STEP);
+    for(int i=0; i<size; i+= inc){
+    //    bzero(data, sizeof(float) * HALF_WINDOW);
+        total_windows = 0;
+        fft->process_buffer(start_position+i,
+            size,
+            copy,
+            get_direction());
+        for(int j = 0; j < HALF_WINDOW; j++)
+            data[j] /= total_windows;
+        send_render_gui(data, HALF_WINDOW);
+    }

+    //printf("Size is: %i\n", size);
+    //printf("Start is: %i\n", start_position);
+
+    delete [] copy;
+
    return 0;
}

@@ -287,22 +306,26 @@
            input1 = input2;
        }

-// Shift left
-        canvas->copy_area(1,
-            0,
-            0,
-            0,
-            canvas->get_w() - 1,
-            canvas->get_h());
-        int x = canvas->get_w() - 1;
-        double scale = (double)0xffffff;
+//Draw the data
+        column %= canvas->get_w();
+        if(column == 0){
+            background++;
+            background %= 3;
+        }
+        int x = column++;
+        //double scale = (double)0xffffff;
+        double scale = (double) 0xff;
        for(int i = 0; i < h; i++)
        {
            int64_t color;
-            color = (int)(scale * temp[i]);
+            int brightness = (int) (scale * temp[i]);
+            brightness = brightness > 0 ? brightness : 0;
+            brightness = brightness < 0xff ? brightness : 0xff;

-            if(color < 0) color = 0;
-            if(color > 0xffffff) color = 0xffffff;
+            color = brightness | brightness << 8 | brightness << 16;
+            color |= 0xff << (background*8) ;
+            color &= ~(0x7f << (background*8)) ; //(0x80 == ~0x7f)
+
            canvas->set_color(color);
            canvas->draw_pixel(x, i);
        }
Index: spectrogram.h
===================================================================
--- spectrogram.h    (revision 1060)
+++ spectrogram.h    (working copy)
@@ -109,6 +109,9 @@
    SpectrogramFFT *fft;
    float *data;
    int total_windows;
+
+    int column;
+    int background;
};