]> git.sesse.net Git - vlc/commitdiff
Made it possible to open a File after vlc was started (you can use vlc now
authorFlorian G. Pflug <fgp@videolan.org>
Thu, 1 Nov 2001 21:52:02 +0000 (21:52 +0000)
committerFlorian G. Pflug <fgp@videolan.org>
Thu, 1 Nov 2001 21:52:02 +0000 (21:52 +0000)
without starting it from the command line)

Cleaned up playlist handling in Intf_Vlc_Wrapper.

plugins/macosx/intf_controller.c
plugins/macosx/intf_controller.h
plugins/macosx/intf_vlc_wrapper.c
plugins/macosx/intf_vlc_wrapper.h

index cbca69a07937eebe7478b3acb17d45148e964fcf..c0186d9a22c048807bce9e4cb6326ea115000c12 100644 (file)
     - (void)applicationDidBecomeActive:(NSNotification*)aNotification {
         if (b_window_is_fullscreen) {
             [o_window orderFront:self] ;
-            [o_vlc play] ;
+            [o_vlc playlistPlayCurrent] ;
         }
     }
     
     - (void)applicationDidResignActive:(NSNotification*)aNotification {
         if (b_window_is_fullscreen) {
-            [o_vlc pause] ;
+            [o_vlc playlistPause] ;
             [o_window orderOut:self] ;
         }
     }
         
         
         
-//Functions attached to user interface         
+//Functions attached to user interface     
+    - (IBAction) openFile:(id)sender {
+        NSOpenPanel *o_panel = [NSOpenPanel openPanel] ;
+        
+        [o_panel setAllowsMultipleSelection:YES] ;
+        if ([o_panel runModalForDirectory:NSHomeDirectory() file:nil types:nil] == NSOKButton) {
+            NSEnumerator* o_files = [[o_panel filenames] objectEnumerator] ;
+            NSString* o_file ;
+            
+            while ((o_file = (NSString*)[o_files nextObject])) {
+                [o_vlc playlistAdd:o_file] ;
+            }
+        }
+        [o_vlc playlistPlayCurrent] ;
+    }
+    
     - (IBAction) pause:(id)sender {
-        [o_vlc pause] ;
+        [o_vlc playlistPause] ;
     }
     
     - (IBAction) play:(id)sender {
-        [o_vlc play] ;
+        [o_vlc playlistPlayCurrent] ;
     }
     
     - (IBAction) timeslider_update:(id)slider {
 @implementation Intf_PlaylistDS
     - (void ) awakeFromNib {
         o_vlc = [Intf_VlcWrapper instance] ;
-        o_playlist = [[NSMutableArray arrayWithCapacity:10] retain] ;
+        o_playlist = nil ;
     }
     
     - (void) readPlaylist {
-        static unsigned int i_length_old = 0;
-        unsigned int i ;
-    
-        if (i_length_old == [o_vlc getPlaylistLength])
-            return ;
-    
-        [o_playlist removeAllObjects] ;
-        [o_vlc lockPlaylist] ;
-        for(i=0; i < [o_vlc getPlaylistLength]; i++)
-            [o_playlist addObject:[o_vlc getPlaylistItem:i]] ;
-        [o_vlc unlockPlaylist] ;
+        o_playlist = [[o_vlc playlistAsArray] retain] ;
     }
 
     - (int) numberOfRowsInTableView:(NSTableView*)o_table {
index 8f1a793db34be2ec93cb6af10ccad2aeeeaa6468..87c175a3bb789585d32c9e6073bdedaeeecbefa2 100644 (file)
@@ -65,6 +65,7 @@
 - (void)applicationDidResignActive:(NSNotification*)aNotification ;
 
 //Functions atteched to user interface 
+- (IBAction) openFile:(id)sender ;
 - (IBAction) pause:(id)sender ;
 - (IBAction) play:(id)sender ;
 - (IBAction) timeslider_update:(id)slider ;
index 9d590b4e79cd6006418d84084dd3381c82b0efba..97e3091519e8fb666a8fc0f4bd43c04228ffcde9 100644 (file)
 
 #define p_area p_main->p_intf->p_input->stream.p_selected_area
 
+@interface Intf_VlcWrapper(Private) 
+- (struct vout_thread_s*) lockVout ;
+- (void) unlockVout ;
+@end
+
 @implementation Intf_VlcWrapper
 //Initialization,.....
     + (Intf_VlcWrapper*) instance {
 
 
 //Playback control
-    - (void) play {
-        if (![self hasInput]) return ;
-    
-        switch (e_speed)
-        {
-            case SPEED_SLOW:
-                input_SetStatus(p_main->p_intf->p_input, INPUT_STATUS_SLOWER) ;
-                break ;
-            case SPEED_NORMAL:
-                input_SetStatus(p_main->p_intf->p_input, INPUT_STATUS_PLAY) ;
-                break ;
-            case SPEED_FAST:
-                input_SetStatus(p_main->p_intf->p_input, INPUT_STATUS_FASTER) ;
-                break ;
-        }
-    }
-    
-    - (void) pause {
-        if (![self hasInput]) return ;
-    
-        input_SetStatus(p_main->p_intf->p_input, INPUT_STATUS_PAUSE) ;
-    }
-    
-    - (void) stop {
-        return ;
-    }
-    
-    - (void) stepf {
-        return ;
-    }
-    
-    - (void) stepr {
-        return ;
-    }
-    
     - (void) setSpeed:(intf_speed_t) _e_speed {
         e_speed = _e_speed ;
-        [self play] ;
+        [self playlistPlayCurrent] ;
     }
     
     - (NSString *) getTimeAsString {
         static char psz_currenttime[ OFFSETTOTIME_MAX_SIZE ] ;
         
-        if (![self hasInput]) return [NSString stringWithCString:"00:00:00"] ;
+        if (!p_main->p_intf->p_input) return [NSString stringWithCString:"00:00:00"] ;
         
         input_OffsetToTime( p_main->p_intf->p_input, psz_currenttime, p_area->i_tell ) ;        
         return [NSString stringWithCString:psz_currenttime] ;
     }
     
     - (float) getTimeAsFloat {
-        if (![self hasInput]) return 0.0 ;
+        if (!p_main->p_intf->p_input) return 0.0 ;
     
         return (float)p_area->i_tell / (float)p_area->i_size ;
     }
 
     - (void) setTimeAsFloat:(float) f_position {
-        if (![self hasInput]) return ;
+        if (!p_main->p_intf->p_input) return ;
     
         input_Seek(p_main->p_intf->p_input, p_area->i_size * f_position) ;
     }
 
     
 //Playlist control
-    - (void) lockPlaylist {
+    - (NSArray*) playlistAsArray {
+        NSMutableArray* p_list = [NSMutableArray arrayWithCapacity:p_main->p_playlist->i_size] ;
+        int i ;
+    
         vlc_mutex_lock(&p_main->p_playlist->change_lock) ;
+        for (i=0; i < p_main->p_playlist->i_size; i++)
+            [p_list addObject:[NSString stringWithCString:p_main->p_playlist->p_item[i].psz_name]] ;
+        vlc_mutex_unlock(&p_main->p_playlist->change_lock) ;
+        
+        return [NSArray arrayWithArray:p_list] ;
     }
+
+     - (int) playlistLength {
+        return p_main->p_playlist->i_size ;
+    }
+    
+    - (NSString*) playlistItem:(int) i_pos {
+        NSString* o_item = nil ;
     
-    - (void) unlockPlaylist {
+        vlc_mutex_lock(&p_main->p_playlist->change_lock) ;
+            if (i_pos < p_main->p_playlist->i_size)
+                o_item = [NSString stringWithCString:p_main->p_playlist->p_item[i_pos].psz_name] ;
         vlc_mutex_unlock(&p_main->p_playlist->change_lock) ;
+                
+        return o_item ;
     }
     
-     - (int) getPlaylistLength {
-        return p_main->p_playlist->i_size ;
+    - (bool) playlistPlayCurrent {
+        if (p_main->p_intf->p_input) {
+            switch (e_speed)
+            {
+                case SPEED_SLOW:
+                    input_SetStatus(p_main->p_intf->p_input, INPUT_STATUS_SLOWER) ;
+                    break ;
+                case SPEED_NORMAL:
+                    input_SetStatus(p_main->p_intf->p_input, INPUT_STATUS_PLAY) ;
+                    break ;
+                case SPEED_FAST:
+                    input_SetStatus(p_main->p_intf->p_input, INPUT_STATUS_FASTER) ;
+                    break ;
+            }
+            p_main->p_playlist->b_stopped = 0 ;
+        }
+        else if (p_main->p_playlist->b_stopped) {
+            if (p_main->p_playlist->i_size)
+                intf_PlaylistJumpto(p_main->p_playlist, p_main->p_playlist->i_index) ;
+            else
+                return FALSE ;
+        }
+        
+        return TRUE ;
+    }
+
+    - (void) playlistPause {
+        if (p_main->p_intf->p_input)
+            input_SetStatus(p_main->p_intf->p_input, INPUT_STATUS_PAUSE) ;
     }
     
-    - (NSString*) getPlaylistItem:(int) i_pos {
-        if (i_pos >= p_main->p_playlist->i_size)
-            return nil ;
-            
-        return [NSString stringWithCString:p_main->p_playlist->p_item[i_pos].psz_name] ;
+    - (void) playlistStop {
+        if (p_main->p_intf->p_input) p_main->p_intf->p_input->b_eof = 1 ;
+        vlc_mutex_lock(&p_main->p_playlist->change_lock) ;
+            p_main->p_playlist->i_index-- ;
+            p_main->p_playlist->b_stopped = 1 ;
+        vlc_mutex_unlock(&p_main->p_playlist->change_lock) ;
     }
     
-    - (void) playNextPlaylistItem {
-        intf_PlaylistNext(p_main->p_playlist) ;
+    - (void) playlistPlayNext {
+        [self playlistStop] ;
+        vlc_mutex_lock(&p_main->p_playlist->change_lock) ;
+            p_main->p_playlist->i_index++ ;
+        vlc_mutex_unlock(&p_main->p_playlist->change_lock) ;
+        [self playlistPlayCurrent] ;
     }
     
-    - (void) playPrevPlaylistItem {
-        intf_PlaylistPrev(p_main->p_playlist) ;
+    - (void) playlistPlayPrev {
+        [self playlistStop] ;
+        vlc_mutex_lock(&p_main->p_playlist->change_lock) ;
+            p_main->p_playlist->i_index-- ;
+        vlc_mutex_unlock(&p_main->p_playlist->change_lock) ;
+        [self playlistPlayCurrent] ;    
+    }
+    
+    - (void) playlistPlayItem:(int)i_item {
+        [self playlistStop] ;
+        vlc_mutex_lock(&p_main->p_playlist->change_lock) ;
+            if (i_item < p_main->p_playlist->i_size)
+                p_main->p_playlist->i_index-- ;
+        vlc_mutex_unlock(&p_main->p_playlist->change_lock) ;        
+        [self playlistPlayCurrent] ;
     }
     
-    - (void) addPlaylistItem:(NSString*)o_filename {
+    - (void) playlistAdd:(NSString*)o_filename {
         intf_PlaylistAdd(p_main->p_playlist, PLAYLIST_END, [o_filename lossyCString]) ;
     }
     
+    - (void) clearPlaylist {
+        int i ;
+    
+        vlc_mutex_lock(&p_main->p_playlist->change_lock) ;
+            for(i=0; i < p_main->p_playlist->i_size; i++)
+                intf_PlaylistDelete(p_main->p_playlist, i) ;
+        vlc_mutex_unlock(&p_main->p_playlist->change_lock) ;        
+    }
+    
 
 
 
 // Private Functions. This are just some utilities for other functions
-    - (bool) hasInput {
-        return (p_main->p_intf->p_input != NULL) ? TRUE : FALSE ;
-    }
-
     - (struct vout_thread_s*) lockVout {
         vlc_mutex_lock(&p_vout_bank->lock) ;
         if (p_vout_bank->i_count) {
index 58da6aa953ded638a41b2de10283afd303c82f41..36c9aad56918269d51c5793aa784b224c12b3beb 100644 (file)
@@ -23,7 +23,6 @@
 
 #import <Cocoa/Cocoa.h>
 
-struct vlc_thread_s ;
 typedef enum intf_speed_e {SPEED_SLOW=0, SPEED_NORMAL, SPEED_FAST} intf_speed_t ;
 @protocol VlcWrapper_Delegate
     - (void) requestQDPortFullscreen:(bool)b_fullscreen ;
@@ -52,28 +51,22 @@ typedef enum intf_speed_e {SPEED_SLOW=0, SPEED_NORMAL, SPEED_FAST} intf_speed_t
 - (NSSize) videoSize ;
 
 // Playback control
-- (void) play ;
-- (void) pause ;
-- (void) stop ;
-- (void) stepf ;
-- (void) stepr ;
 - (void) setSpeed:(intf_speed_t)e_speed ;
 - (NSString*) getTimeAsString ;
 - (float) getTimeAsFloat ;
 - (void) setTimeAsFloat:(float)i_offset ;
 
 // Playlist control
-- (void) lockPlaylist ;
-- (void) unlockPlaylist ;
-- (int) getPlaylistLength ;
-- (NSString*) getPlaylistItem:(int)i_pos ;
-- (void) playNextPlaylistItem ;
-- (void) playPrevPlaylistItem ;
-- (void) addPlaylistItem:(NSString*)o_filename ;
-
-//private
-- (bool) hasInput ;
-- (struct vout_thread_s*) lockVout ;
-- (void) unlockVout ;
+- (NSArray*) playlistAsArray ;
+- (int) playlistLength ;
+- (NSString*) playlistItem:(int) i_pos ;
+- (bool) playlistPlayCurrent ;
+- (void) playlistPause ;
+- (void) playlistStop ;
+- (void) playlistPlayNext ;
+- (void) playlistPlayPrev ;
+- (void) playlistPlayItem:(int)i_item ;
+- (void) playlistAdd:(NSString*)o_filename ;
+- (void) clearPlaylist ;
 @end