]> git.sesse.net Git - vlc/blobdiff - modules/gui/macosx/equalizer.m
macosx: merge Eric Dudiak's code from GSoC 2008
[vlc] / modules / gui / macosx / equalizer.m
index d570baf6bc08fee3f87443de658c9be8d5aa6b4b..367ff0b477a29eb60dec7fb927c471baf6f37b79 100644 (file)
 /*****************************************************************************
  * Preamble
  *****************************************************************************/
-#include <vlc/vlc.h>
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <vlc_common.h>
 #include <vlc_aout.h>
 
 #include "intf.h"
 @implementation VLCEqualizer
 
 static void ChangeFiltersString( intf_thread_t *p_intf,
-                                 char *psz_name, vlc_bool_t b_add )
+                                 char *psz_name, bool b_add )
 {
     char *psz_parser, *psz_string;
     int i;
     vlc_object_t *p_object = vlc_object_find( p_intf,
                                 VLC_OBJECT_AOUT, FIND_ANYWHERE );
     aout_instance_t *p_aout = (aout_instance_t *)p_object;
-    if( p_object == NULL )
-        p_object = vlc_object_find( p_intf,
-                                 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
-    if( p_object == NULL )
-        return;
+    if( !p_object )
+    {
+        p_object = (vlc_object_t *)pl_Hold( p_intf );
+    }
 
     psz_string = var_GetNonEmptyString( p_object, "audio-filter" );
 
@@ -71,6 +74,7 @@ static void ChangeFiltersString( intf_thread_t *p_intf,
         }
         else
         {
+            vlc_object_release( p_object );
             return;
         }
     }
@@ -89,8 +93,9 @@ static void ChangeFiltersString( intf_thread_t *p_intf,
          }
          else
          {
-             free( psz_string );
-             return;
+            free( psz_string );
+            vlc_object_release( p_object );
+            return;
          }
     }
 
@@ -99,7 +104,7 @@ static void ChangeFiltersString( intf_thread_t *p_intf,
     {
         for( i = 0; i < p_aout->i_nb_inputs; i++ )
         {
-            p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
+            p_aout->pp_inputs[i]->b_restart = true;
         }
     }
     
@@ -107,26 +112,20 @@ static void ChangeFiltersString( intf_thread_t *p_intf,
     {
         /* save changed to config */
         config_PutPsz( p_object, "audio-filter", psz_string );
-
-        /* save to vlcrc */
-        config_SaveConfigFile( p_object, "main" );
     }
     
     free( psz_string );
     vlc_object_release( p_object );
 }
 
-static vlc_bool_t GetFiltersStatus( intf_thread_t *p_intf,
+static bool GetFiltersStatus( intf_thread_t *p_intf,
                                  char *psz_name )
 {
     char *psz_parser, *psz_string;
     vlc_object_t *p_object = vlc_object_find( p_intf,
                                 VLC_OBJECT_AOUT, FIND_ANYWHERE );
     if( p_object == NULL )
-        p_object = vlc_object_find( p_intf,
-                                 VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
-    if( p_object == NULL )
-        return VLC_FALSE;
+        p_object = (vlc_object_t *)pl_Hold( p_intf );
 
     if( (BOOL)config_GetInt( p_intf, "macosx-eq-keep" ) == YES )
         psz_string = config_GetPsz( p_intf, "audio-filter" );
@@ -136,22 +135,23 @@ static vlc_bool_t GetFiltersStatus( intf_thread_t *p_intf,
 
     vlc_object_release( p_object );
 
-    if( !psz_string ) return VLC_FALSE;
+    if( !psz_string ) return false;
 
     psz_parser = strstr( psz_string, psz_name );
 
     free( psz_string );
 
     if ( psz_parser )
-        return VLC_TRUE;
+        return true;
     else
-        return VLC_FALSE;
+        return false;
 }
 
 - (void)initStrings
 {
     int i;
     [o_btn_equalizer setToolTip: _NS("Equalizer")];
+    [o_btn_equalizer_embedded setToolTip: _NS("Equalizer")];
     [o_ckb_2pass setTitle: _NS("2 Pass")];
     [o_ckb_2pass setToolTip: _NS("Apply the "
         "equalizer filter twice. The effect will be sharper.")];
@@ -175,17 +175,14 @@ static vlc_bool_t GetFiltersStatus( intf_thread_t *p_intf,
     intf_thread_t *p_intf = VLCIntf;
     float f_preamp, f_band[10];
     char *psz_bands, *psz_bands_init, *p_next;
-    vlc_bool_t b_2p;
+    bool b_2p;
     int i;
-    vlc_bool_t b_enabled = GetFiltersStatus( p_intf, (char *)"equalizer" );
+    bool b_enabled = GetFiltersStatus( p_intf, (char *)"equalizer" );
     vlc_object_t *p_object = vlc_object_find( p_intf,
                                               VLC_OBJECT_AOUT, FIND_ANYWHERE );
 
     if( p_object == NULL )
-        p_object = vlc_object_find( p_intf,
-                                    VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
-    if( p_object == NULL )
-        return;
+        p_object = (vlc_object_t *)pl_Hold( p_intf );
 
     var_Create( p_object, "equalizer-preamp", VLC_VAR_FLOAT |
                 VLC_VAR_DOINHERIT );
@@ -219,11 +216,7 @@ static vlc_bool_t GetFiltersStatus( intf_thread_t *p_intf,
     for( i = 0; i < 10; i++ )
     {
         /* Read dB -20/20 */
-#ifdef HAVE_STRTOF
         f_band[i] = strtof( psz_bands, &p_next );
-#else
-        f_band[i] = (float)strtod( psz_bands, &p_next );
-#endif
         if( !p_next || p_next == psz_bands ) break; /* strtof() failed */
     
         if( !*psz_bands ) break; /* end of line */
@@ -245,10 +238,7 @@ static vlc_bool_t GetFiltersStatus( intf_thread_t *p_intf,
                                               VLC_OBJECT_AOUT, FIND_ANYWHERE );
 
     if( p_object == NULL )
-        p_object = vlc_object_find( p_intf,
-                                    VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
-    if( p_object == NULL )
-        return;
+        p_object = (vlc_object_t *)pl_Hold( p_intf );
 
     char psz_values[102];
     memset( psz_values, 0, 102 );
@@ -288,10 +278,7 @@ static vlc_bool_t GetFiltersStatus( intf_thread_t *p_intf,
     vlc_object_t *p_object= vlc_object_find( p_intf,
                                              VLC_OBJECT_AOUT, FIND_ANYWHERE );
     if( p_object == NULL )
-        p_object = vlc_object_find( p_intf,
-                                    VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
-    if( p_object == NULL )
-        return;
+        p_object = (vlc_object_t *)pl_Hold( p_intf );
 
     char psz_values[102];
     memset( psz_values, 0, 102 );
@@ -334,10 +321,7 @@ static vlc_bool_t GetFiltersStatus( intf_thread_t *p_intf,
     vlc_object_t *p_object = vlc_object_find( p_intf,
                                               VLC_OBJECT_AOUT, FIND_ANYWHERE );
     if( p_object == NULL )
-        p_object = vlc_object_find( p_intf,
-                                    VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
-    if( p_object == NULL )
-        return;
+        p_object = (vlc_object_t *)pl_Hold( p_intf );
 
     var_SetFloat( p_object, "equalizer-preamp", f_preamp );
 
@@ -359,26 +343,25 @@ static vlc_bool_t GetFiltersStatus( intf_thread_t *p_intf,
     {
         [o_window orderOut:sender];
         [o_btn_equalizer setState:NSOffState];
+        [o_btn_equalizer_embedded setState:NSOffState];
     }
     else
     {
         [o_window makeKeyAndOrderFront:sender];
         [o_btn_equalizer setState:NSOnState];
+        [o_btn_equalizer_embedded setState:NSOnState];
     }
 }
 
 - (IBAction)twopass:(id)sender
 {
     intf_thread_t *p_intf = VLCIntf;
-    vlc_bool_t b_2p = [sender state] ? VLC_TRUE : VLC_FALSE;
+    bool b_2p = [sender state] ? true : false;
     vlc_object_t *p_object= vlc_object_find( p_intf,
                                              VLC_OBJECT_AOUT, FIND_ANYWHERE );
     aout_instance_t *p_aout = (aout_instance_t *)p_object;
     if( p_object == NULL )
-        p_object = vlc_object_find( p_intf,
-                                    VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
-    if( p_object == NULL )
-        return;
+        p_object = (vlc_object_t *)pl_Hold( p_intf );
 
     var_SetBool( p_object, "equalizer-2pass", b_2p );
     if( ( [o_ckb_enable state] ) && ( p_aout != NULL ) )
@@ -386,7 +369,7 @@ static vlc_bool_t GetFiltersStatus( intf_thread_t *p_intf,
         int i;
         for( i = 0; i < p_aout->i_nb_inputs; i++ )
         {
-            p_aout->pp_inputs[i]->b_restart = VLC_TRUE;
+            p_aout->pp_inputs[i]->b_restart = true;
         }
     }
 
@@ -413,8 +396,7 @@ static vlc_bool_t GetFiltersStatus( intf_thread_t *p_intf,
     vlc_object_t *p_object= vlc_object_find( VLCIntf,
                                              VLC_OBJECT_AOUT, FIND_ANYWHERE );
     if( p_object == NULL )
-        p_object = vlc_object_find( VLCIntf,
-                                    VLC_OBJECT_PLAYLIST, FIND_ANYWHERE );
+        p_object = (vlc_object_t *)pl_Hold( VLCIntf );
 
     [o_window setExcludedFromWindowsMenu: TRUE];
 
@@ -474,7 +456,7 @@ static vlc_bool_t GetFiltersStatus( intf_thread_t *p_intf,
 }
 
 
-- (id)getSliderByIndex:(int)index
+- (id)sliderByIndex:(int)index
 {
     switch(index)
     {
@@ -512,7 +494,7 @@ static vlc_bool_t GetFiltersStatus( intf_thread_t *p_intf,
 
 - (void)setValue:(float)value forSlider:(int)index
 {
-    id slider = [self getSliderByIndex:index];
+    id slider = [self sliderByIndex:index];
 
     if (slider != nil)
     {