Merged 15170:15635 from trunk (no conflicts or even merges)
[blender.git] / source / blender / src / editsound.c
index bd209f2d39c94da1d79ab7879d1ad114822eb842..05eb094a7c21a3b13b8533eb62c27ed623afb719 100644 (file)
@@ -1,15 +1,12 @@
 /**
  * $Id$
  *
- * ***** BEGIN GPL/BL DUAL LICENSE BLOCK *****
+ * ***** BEGIN GPL LICENSE BLOCK *****
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version. The Blender
- * Foundation also sells licenses for use in proprietary software under
- * the Blender License.  See http://www.blender.org/BL/ for information
- * about this.
+ * of the License, or (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -27,7 +24,7 @@
  *
  * Contributor(s): none yet.
  *
- * ***** END GPL/BL DUAL LICENSE BLOCK *****
+ * ***** END GPL LICENSE BLOCK *****
  */
 
 #include <stdio.h>
 #include "BIF_interface.h"
 #include "BIF_editsound.h"
 #include "BIF_mywindow.h"
+#include "BIF_toolbox.h"
 
 #include "BSE_drawipo.h"
 #include "BSE_headerbuttons.h"
+#include "BSE_time.h"
+
+#include "BDR_editobject.h"
 
 #include "blendef.h"
 
@@ -119,7 +120,7 @@ void winqreadsoundspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
 
        if(val) {
                
-               if( uiDoBlocks(&curarea->uiblocks, event)!=UI_NOTHING ) event= 0;
+               if( uiDoBlocks(&curarea->uiblocks, event, 1)!=UI_NOTHING ) event= 0;
 
                /* swap mouse buttons based on user preference */
                if (U.flag & USER_LMOUSESELECT) {
@@ -139,7 +140,7 @@ void winqreadsoundspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                getmouseco_areawin(mval);
                                areamouseco_to_ipoco(G.v2d, mval, &dx, &dy);
                                
-                               cfra = (int)dx;
+                               cfra = (int)(dx+0.5f);
                                if(cfra< 1) cfra= 1;
                                
                                if( cfra!=CFRA || first )
@@ -147,7 +148,7 @@ void winqreadsoundspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                                        first= 0;
                                        CFRA= cfra;
                                        update_for_newframe();
-                                       force_draw_plus(SPACE_VIEW3D, 1);
+                                       force_draw_all(0);
                                }
                                else PIL_sleep_ms(30);
                        
@@ -163,14 +164,28 @@ void winqreadsoundspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                        view2dmove(event);      /* in drawipo.c */
                        break;
                case RIGHTMOUSE:
-                       nr= pupmenu("Time value%t|Frames %x1|Seconds%x2");
-                       if (nr>0) {
-                               if(nr==1) ssound->flag |= SND_DRAWFRAMES;
-                               else ssound->flag &= ~SND_DRAWFRAMES;
-                               doredraw= 1;
-                       }
+                       {
+                               TimeMarker *marker;
+                               
+                               getmouseco_areawin(mval);
+                               areamouseco_to_ipoco(G.v2d, mval, &dx, &dy);
 
+                               marker = find_nearest_marker(SCE_MARKERS, 0);
+                               if (marker) {
+                                       if ((G.qual & LR_SHIFTKEY)==0)
+                                               deselect_markers(0, 0);
+                                               
+                                       if (marker->flag & SELECT)
+                                               marker->flag &= ~SELECT;
+                                       else
+                                               marker->flag |= SELECT;
+                               }
+                               
+                               force_draw(0);
+                               std_rmouse_transform(transform_markers);
+                       }
                        break;
+                       
                case PADPLUSKEY:
                        dx= (float)(0.1154*(G.v2d->cur.xmax-G.v2d->cur.xmin));
                        G.v2d->cur.xmin+= dx;
@@ -190,6 +205,62 @@ void winqreadsoundspace(ScrArea *sa, void *spacedata, BWinEvent *evt)
                case HOMEKEY:
                        do_sound_buttons(B_SOUNDHOME);
                        break;
+                       
+               case PAGEUPKEY: /* cfra to next marker */
+                       nextprev_marker(1);
+                       break;
+               case PAGEDOWNKEY: /* cfra to prev marker */
+                       nextprev_marker(-1);
+                       break;
+               
+               case AKEY: /* select/deselect all  */
+                       deselect_markers(1, 0);
+                       
+                       allqueue(REDRAWMARKER, 0);
+                       break;
+                       
+               case BKEY: /* borderselect markers */
+                       borderselect_markers();
+                       break;
+               
+               case DKEY: /* duplicate selected marker(s) */
+                       if (G.qual & LR_SHIFTKEY) {
+                               duplicate_marker();
+                               
+                               allqueue(REDRAWMARKER, 0);
+                       }
+                       break;
+                       
+               case GKEY:
+                       transform_markers('g', 0);
+                       break;
+                       
+               case MKEY: /* add marker or rename first selected */
+                       if (G.qual & LR_CTRLKEY)
+                               rename_marker();
+                       else
+                               add_marker(CFRA);
+                       
+                       allqueue(REDRAWMARKER, 0);
+                       break;          
+               
+               case TKEY: /* toggle time display */
+                       nr= pupmenu("Time value%t|Frames %x1|Seconds%x2");
+                       if (nr>0) {
+                               if(nr==1) ssound->flag |= SND_DRAWFRAMES;
+                               else ssound->flag &= ~SND_DRAWFRAMES;
+                               doredraw= 1;
+                       }
+
+                       break;
+                       
+               case DELKEY: /* delete selected markers */
+               case XKEY:
+                       if (okee("Erase selected")) {
+                               remove_marker();
+                               allqueue(REDRAWMARKER, 0);
+                       }
+                       break;
                }
        }
 
@@ -642,7 +713,7 @@ bSound *sound_new_sound(char *name)
        if (!G.scene->audio.mixrate) G.scene->audio.mixrate = 44100;
        /* convert the name to absolute path */
        strcpy(str, name);
-       BLI_convertstringcode(str, G.sce, G.scene->r.cfra);
+       BLI_convertstringcode(str, G.sce);
 
        /* check if the sample on disk can be opened */
        file = open(str, O_BINARY|O_RDONLY);
@@ -724,6 +795,7 @@ int sound_set_sample(bSound *sound, bSample *sample)
 
 bSample *sound_new_sample(bSound *sound)
 {
+       char samplename[FILE_MAX];
        bSample *sample = NULL;
        int len;
        char *name;
@@ -750,9 +822,12 @@ bSample *sound_new_sample(bSound *sound)
                sample->alindex = SAMPLE_INVALID;
 
                /* convert sound->name to abolute filename */
-               strcpy(sample->name, sound->name);
-               BLI_convertstringcode(sample->name, G.sce, G.scene->r.cfra);
-               
+               /* TODO: increase sound->name, sample->name and strip->name to FILE_MAX, to avoid
+                  cutting off sample name here - elubie */
+               BLI_strncpy(samplename, sound->name, FILE_MAX);         
+               BLI_convertstringcode(samplename, G.sce);
+               BLI_strncpy(sample->name, samplename, FILE_MAXDIR);
+
                /* connect the pf to the sample */
                if (sound->newpackedfile)
                        sample->packedfile = sound->newpackedfile;
@@ -774,13 +849,13 @@ bSample *sound_find_sample(bSound *sound)
        
        // convert sound->name to abolute filename
        strcpy(name, sound->name);
-       BLI_convertstringcode(name, G.sce, G.scene->r.cfra);
+       BLI_convertstringcode(name, G.sce);
        
        /* search through the list of loaded samples */
        sample = samples->first;
        while (sample) {
                strcpy(samplename, sample->name);
-               BLI_convertstringcode(samplename, G.sce, G.scene->r.cfra);
+               BLI_convertstringcode(samplename, G.sce);
                
                if (strcmp(name, samplename) == 0)      {
                        break;