usb_direct fix for rev2 shuttle, playbackengine locks again, viewer cursor fix
authorGood Guy <[email protected]>
Sat, 16 Feb 2019 01:44:27 +0000 (18:44 -0700)
committerGood Guy <[email protected]>
Sat, 16 Feb 2019 01:44:27 +0000 (18:44 -0700)
12 files changed:
cinelerra-5.1/cinelerra/awindowgui.C
cinelerra-5.1/cinelerra/playbackengine.C
cinelerra-5.1/cinelerra/playbackengine.h
cinelerra-5.1/cinelerra/renderengine.C
cinelerra-5.1/cinelerra/shudmp.C
cinelerra-5.1/cinelerra/shuttle.C
cinelerra-5.1/cinelerra/trackcanvas.C
cinelerra-5.1/guicast/bcscrollbar.C
cinelerra-5.1/guicast/bcwindowbase.C
cinelerra-5.1/guicast/bcwindowbase.h
cinelerra-5.1/libzmpeg3/audio/layer3.C
cinelerra-5.1/shuttlerc

index 65e5ba2591b5c30782a936f69fcb27097cfca339..8b53f7ad594b1cb7a61d0e3f7390307e23570624 100644 (file)
@@ -398,7 +398,7 @@ int AssetViewPopup::button_press_event()
                vedl->set_inpoint(start);
                vedl->set_outpoint(end);
                vedl->local_session->set_selectionstart(start);
-               vedl->local_session->set_selectionend(end);
+               vedl->local_session->set_selectionend(start);
                vwindow->gui->lock_window("AssetViewPopup::button_press_event");
                vwindow->update_position();
                vwindow->gui->unlock_window();
index 0dd9b37f1e943dfd5db3406cc84779fc61e8c83a..16f6bd7a73c65bda3ffd6065186063eefe206f58 100644 (file)
@@ -128,26 +128,25 @@ int PlaybackEngine::create_render_engine()
 void PlaybackEngine::delete_render_engine()
 {
        renderengine_lock->lock("PlaybackEngine::delete_render_engine");
-       delete render_engine;
-       render_engine = 0;
+       delete render_engine;  render_engine = 0;
        renderengine_lock->unlock();
 }
 
 void PlaybackEngine::arm_render_engine()
 {
-       if(render_engine)
+       if( render_engine )
                render_engine->arm_command(command);
 }
 
 void PlaybackEngine::start_render_engine()
 {
-       if(render_engine) render_engine->start_command();
+       if( render_engine )
+               render_engine->start_command();
 }
 
 void PlaybackEngine::wait_render_engine()
 {
-       if(command->realtime && render_engine)
-       {
+       if( command->realtime && render_engine ) {
                render_engine->join();
        }
 }
@@ -180,14 +179,14 @@ void PlaybackEngine::sync_parameters(EDL *edl)
 {
 // TODO: lock out render engine from keyframe deletions
        command->get_edl()->synchronize_params(edl);
-       if(render_engine) render_engine->get_edl()->synchronize_params(edl);
+       if( render_engine )
+               render_engine->get_edl()->synchronize_params(edl);
 }
 
-
 void PlaybackEngine::interrupt_playback(int wait_tracking)
 {
        renderengine_lock->lock("PlaybackEngine::interrupt_playback");
-       if(render_engine)
+       if( render_engine )
                render_engine->interrupt_playback();
        renderengine_lock->unlock();
 
@@ -195,22 +194,19 @@ void PlaybackEngine::interrupt_playback(int wait_tracking)
        pause_lock->unlock();
 
 // Wait for tracking to finish if it is running
-       if(wait_tracking)
-       {
+       if( wait_tracking ) {
                tracking_done->lock("PlaybackEngine::interrupt_playback");
                tracking_done->unlock();
        }
 }
 
-
 // Return 1 if levels exist
 int PlaybackEngine::get_output_levels(double *levels, long position)
 {
        int result = 0;
-       if(render_engine && render_engine->do_audio)
-       {
-               result = 1;
+       if( render_engine && render_engine->do_audio ) {
                render_engine->get_output_levels(levels, position);
+               result = 1;
        }
        return result;
 }
@@ -219,10 +215,9 @@ int PlaybackEngine::get_output_levels(double *levels, long position)
 int PlaybackEngine::get_module_levels(ArrayList<double> *module_levels, long position)
 {
        int result = 0;
-       if(render_engine && render_engine->do_audio)
-       {
-               result = 1;
+       if( render_engine && render_engine->do_audio ) {
                render_engine->get_module_levels(module_levels, position);
+               result = 1;
        }
        return result;
 }
@@ -287,10 +282,8 @@ double PlaybackEngine::get_tracking_position()
 
 
 // Don't interpolate when every frame is played.
-               if(command->get_edl()->session->video_every_frame &&
-                       render_engine &&
-                       render_engine->do_video)
-               {
+               if( command->get_edl()->session->video_every_frame &&
+                   render_engine && render_engine->do_video ) {
                        result = tracking_position;
                }
                else
@@ -422,7 +415,7 @@ void PlaybackEngine::stop_playback(int wait_tracking)
 {
        transport_stop(wait_tracking);
        renderengine_lock->lock("PlaybackEngine::stop_playback");
-       if(render_engine)
+       if( render_engine )
                render_engine->wait_done();
        renderengine_lock->unlock();
 }
@@ -491,12 +484,23 @@ void PlaybackEngine::send_command(int command, EDL *edl, int wait_tracking, int
        }
 }
 
-int PlaybackEngine::transport_stop(int wait_tracking)
+int PlaybackEngine::put_command(TransportCommand *command, int reset)
 {
-       interrupt_playback(0);
-       input_lock->lock("PlaybackEngine::transport_stop");
-       sent_command->copy_from(stop_command);
+// commands can deadlock updating tracking,meters,clock...
+       int mlocked = mwindow->gui->break_lock();
+       input_lock->lock("PlaybackEngine::put_command");
+       sent_command->copy_from(command);
+       if( reset )
+               command->reset();
        output_lock->unlock();
+       if( mlocked )
+               mwindow->gui->lock_window("PlaybackEngine::put_command");
+       return 0;
+}
+
+int PlaybackEngine::transport_stop(int wait_tracking)
+{
+       put_command(stop_command, 0);
        if( wait_tracking ) {
                tracking_done->lock("PlaybackEngine::transport_stop");
                tracking_done->unlock();
@@ -525,13 +529,7 @@ int PlaybackEngine::transport_command(int command, int change_type, EDL *new_edl
                next_command->set_playback_range(new_edl, use_inout,
                                preferences->forward_render_displacement);
        }
-
-       interrupt_playback(0);
-       input_lock->lock("PlaybackEngine::transport_command");
-       sent_command->copy_from(next_command);
-       next_command->reset();
-       output_lock->unlock();
-
+       put_command(next_command, 1);
 //static const char *types[] = { "NONE",
 // "FRAME_FWD", "NORMAL_FWD", "FAST_FWD", "FRAME_REV", "NORMAL_REV", "FAST_REV",
 // "STOP",  "PAUSE", "SLOW_FWD", "SLOW_REV", "REWIND", "GOTO_END", "CURRENT_FRAME",
index 29632529e74e3bbbcbcc22015231eb5faacc4e63..62616822b7ccf3c0012d649972419eb2acab8434 100644 (file)
@@ -110,6 +110,7 @@ public:
 // Copy of main preferences
        Preferences *preferences;
 
+       int put_command(TransportCommand *command, int reset);
        int transport_stop(int wait_tracking);
        int transport_command(int command, int change_type=CHANGE_NONE,
                        EDL *new_edl=0, int use_inout=0);
index 3c178bb07f8765246ddcaf3704c7866804ce4022..9b640d20e2ada9e5467960654c4fd1f9f267015b 100644 (file)
@@ -349,13 +349,9 @@ int64_t RenderEngine::sync_position()
 // Use audio device
 // No danger of race conditions because the output devices are closed after all
 // threads join.
-       if(do_audio)
-       {
+       if( do_audio )
                return audio->current_position();
-       }
-
-       if(do_video)
-       {
+       if( do_video ) {
                int64_t result = timer.get_scaled_difference(
                        get_edl()->session->sample_rate);
                return result;
@@ -366,8 +362,7 @@ int64_t RenderEngine::sync_position()
 
 int RenderEngine::start_command()
 {
-       if(command->realtime && !is_nested)
-       {
+       if( command->realtime && !is_nested ) {
                interrupt_lock->lock("RenderEngine::start_command");
                start_lock->lock("RenderEngine::start_command 1");
                Thread::start();
@@ -379,15 +374,8 @@ int RenderEngine::start_command()
 
 void RenderEngine::arm_render_threads()
 {
-       if(do_audio)
-       {
-               arender->arm_command();
-       }
-
-       if(do_video)
-       {
-               vrender->arm_command();
-       }
+       if( do_audio ) arender->arm_command();
+       if( do_video ) vrender->arm_command();
 }
 
 
@@ -396,15 +384,10 @@ void RenderEngine::start_render_threads()
 // Synchronization timer.  Gets reset once again after the first video frame.
        timer.update();
 
-       if(do_audio)
-       {
-               arender->start_command();
-       }
+       if( do_audio ) arender->start_command();
+       if( do_video ) vrender->start_command();
 
-       if(do_video)
-       {
-               vrender->start_command();
-       }
+       start_lock->unlock();
 }
 
 void RenderEngine::update_framerate(float framerate)
@@ -415,29 +398,18 @@ void RenderEngine::update_framerate(float framerate)
 
 void RenderEngine::wait_render_threads()
 {
-       if(do_audio)
-       {
-               arender->Thread::join();
-       }
-
-       if(do_video)
-       {
-               vrender->Thread::join();
-       }
+       if( do_audio ) arender->Thread::join();
+       if( do_video ) vrender->Thread::join();
 }
 
 void RenderEngine::interrupt_playback()
 {
+       if( interrupted ) return;
        interrupt_lock->lock("RenderEngine::interrupt_playback");
-       interrupted = 1;
-       if(do_audio && arender)
-       {
-               arender->interrupt_playback();
-       }
-
-       if(do_video && vrender)
-       {
-               vrender->interrupt_playback();
+       if( !interrupted ) {
+               interrupted = 1;
+               if( do_audio && arender ) arender->interrupt_playback();
+               if( do_video && vrender ) vrender->interrupt_playback();
        }
        interrupt_lock->unlock();
 }
@@ -445,25 +417,15 @@ void RenderEngine::interrupt_playback()
 int RenderEngine::close_output()
 {
 // Nested engines share devices
-       if(!is_nested)
-       {
-               if(audio)
-               {
-                       audio->close_all();
-                       delete audio;
-                       audio = 0;
-               }
-
-
-
-               if(video)
-               {
-                       video->close_all();
-                       delete video;
-                       video = 0;
-               }
+       if( is_nested ) return 0;
+       if( audio ) {
+               audio->close_all();
+               delete audio;  audio = 0;
+       }
+       if( video ) {
+               video->close_all();
+               delete video;  video = 0;
        }
-
        return 0;
 }
 
@@ -497,58 +459,33 @@ void RenderEngine::get_module_levels(ArrayList<double> *module_levels, int64_t p
 void RenderEngine::run()
 {
        render_active->lock("RenderEngine::run");
-       start_render_threads();
-       start_lock->unlock();
-       interrupt_lock->unlock();
 
+       interrupt_lock->unlock();
+       start_render_threads();
        wait_render_threads();
-
-       interrupt_lock->lock("RenderEngine::run");
-
-
-       if(interrupted)
-       {
-               playback_engine->tracking_position = playback_engine->get_tracking_position();
-       }
+       interrupt_lock->lock("RenderEngine::wait_render_threads");
 
        close_output();
 
-// Fix the tracking position
-       if(playback_engine)
-       {
-               if(command->command == CURRENT_FRAME || command->command == LAST_FRAME)
-               {
-//printf("RenderEngine::run 4.1 %d\n", playback_engine->tracking_position);
-                       playback_engine->tracking_position = command->playbackstart;
-               }
-               else
-               {
-// Make sure transport doesn't issue a pause command next
-//printf("RenderEngine::run 4.1 %d\n", playback_engine->tracking_position);
-                       if(!interrupted)
-                       {
-                               playback_engine->tracking_position =
-                                       command->get_direction() == PLAY_FORWARD ?
-                                               command->end_position : command->start_position;
-                       }
-
-                       if( playback_engine->is_playing_back && command->displacement ) {
-                               double position = playback_engine->tracking_position -
-                                       1./command->get_edl()->session->frame_rate;
-                               playback_engine->tracking_position = position >= 0 ? position : 0;
-                       }
-
-                       if( !interrupted )
-                               playback_engine->command->command = STOP;
-                       playback_engine->stop_tracking();
-
+       if( playback_engine && playback_engine->is_playing_back ) {
+               double position = interrupted ?
+                       playback_engine->get_tracking_position() :
+                       command->get_direction() == PLAY_FORWARD ?
+                               command->end_position :
+                               command->start_position;
+               playback_engine->command->command = STOP;
+               if( playback_engine->is_playing_back && command->displacement ) {
+                       position -= 1./command->get_edl()->session->frame_rate;
+                       if( position < 0 ) position = 0;
                }
                playback_engine->is_playing_back = 0;
+               playback_engine->tracking_position = position;
+               playback_engine->stop_tracking();
        }
 
-       input_lock->unlock();
-       interrupt_lock->unlock();
        render_active->unlock();
+       interrupt_lock->unlock();
+       input_lock->unlock();
 }
 
 void RenderEngine::wait_done()
index fbb85cf68af3746754e896743f20960cd651ecdc..ae31aceba08f3ce9adad99a06e45b9f54da7757d 100644 (file)
@@ -58,7 +58,7 @@ int main(int ac, char **av)
                while( !done ) {
                        int len = 0;
                        static const int IN_ENDPOINT = 0x81;
-                       unsigned char dat[64];
+                       unsigned char dat[5];
                        int ret = libusb_interrupt_transfer(devsh,
                                        IN_ENDPOINT, dat, sizeof(dat), &len, 100);
                        if( ret != 0 ) {
index 22adeaf01180c29609e9d3280870313bc84ad403..7bf3c5e486df18739192dce8119758274b3c7f6f 100644 (file)
@@ -847,7 +847,7 @@ void Shuttle::run()
        while( devsh && !done ) {
                int len = 0;
                static const int IN_ENDPOINT = 0x81;
-               unsigned char dat[BCSTRLEN];
+               unsigned char dat[5];
                int ret = libusb_interrupt_transfer(devsh,
                                IN_ENDPOINT, dat, sizeof(dat), &len, 100);
                if( ret != 0 ) {
index ab93d6234d03897e8586978a2ac8de3cc60dc66a..4b1c2364397f64c68f72b14b5d0b9c93c1dc9981 100644 (file)
@@ -3993,7 +3993,7 @@ int TrackCanvas::update_drag_floatauto(int cursor_x, int cursor_y)
 // Snap to nearby values
                old_value = current->get_value();
                if(shift_down()) {
-                       double value1, value2, distance1, distance2;
+                       double value1, value2, distance1=-1, distance2=-1;
 
                        if(current->previous) {
                                int autogrouptype = current->previous->autos->autogrouptype;
index 680341d0beebf0e990e1b74a5bf42c62670e9473..a148bc305383fd1ec01b435ff043e687a1f50a0e 100644 (file)
@@ -86,16 +86,14 @@ void BC_ScrollBar::set_images(VFrame **data)
 
 void BC_ScrollBar::calculate_dimensions(int &w, int &h)
 {
-       switch(orientation)
-       {
+       w = h = pixels;
+       switch( orientation ) {
                case SCROLL_HORIZ:
-                       w = pixels;
                        h = data[SCROLL_HANDLE_UP]->get_h();
                        break;
 
                case SCROLL_VERT:
                        w = data[SCROLL_HANDLE_UP]->get_w();
-                       h = pixels;
                        break;
        }
 }
index f9e49e22aa897e2059dd1973cbf04885298a68b5..099f82494eb8a637977f2cc03cafef61fd4721bd 100644 (file)
@@ -3334,6 +3334,23 @@ int BC_WindowBase::unlock_window()
        return 0;
 }
 
+int BC_WindowBase::break_lock()
+{
+       if( !top_level ) return 0;
+       if( top_level != this ) return top_level->break_lock();
+       if( top_level->display_lock_owner != pthread_self() ) return 0;
+       if( top_level->window_lock != 1 ) return 0;
+       UNSET_LOCK(this);
+       window_lock = 0;
+       display_lock_owner = 0;
+#ifdef SINGLE_THREAD
+       BC_Display::unlock_display();
+#else
+       XUnlockDisplay(display);
+#endif
+       return 1;
+}
+
 void BC_WindowBase::set_done(int return_value)
 {
        if(done_set) return;
index b512820d92fe93763fb35ce72ca0f3ff551a6a18..7dfc26fd1ec4fb610f4bff928ec0e176e1993cb7 100644 (file)
@@ -251,6 +251,7 @@ public:
        int lock_window(const char *location = 0);
        int unlock_window();
        int get_window_lock();
+       int break_lock();
 
        BC_MenuBar* add_menubar(BC_MenuBar *menu_bar);
        BC_WindowBase* add_subwindow(BC_WindowBase *subwindow);
index b0eb290976dd8009cf7913798e37c8c1ac35d2c7..d8f1897040c9fa713922b32663fbc1071bdc96a7 100644 (file)
@@ -742,7 +742,7 @@ do_layer3(uint8_t *zframe, int zframe_size, float **zoutput, int render)
   /* max 39 for short[13][3] mode, mixed: 38, long: 22 */
   int scalefacs[2][39]; 
   l3_sideinfo_t sideinfo;
-  int ms_stereo, i_stereo;
+  int ms_stereo=0, i_stereo=0;
   int sfreq = sampling_frequency_code;
   int stereo1, granules;
   int output_offset = 0;
@@ -798,8 +798,8 @@ do_layer3(uint8_t *zframe, int zframe_size, float **zoutput, int render)
       ptr = bsbuf + ssize - prev_len;
       memcpy(ptr, prev, prev_len);
       past_framesize += prev_framesize;
-    }
-//}
+//  }
+  }
   if( ptr && past_framesize >= prev_len ) {
     stream->use_ptr(ptr);
     for( gr=0; gr<granules; ++gr ) {
index 0c9affbfdf326035ea64cb4eeeea0d4393a91f91..9091c5ddbe56d4ab551e2a1fea73b0cbc5264e61 100644 (file)
@@ -1,7 +1,7 @@
 
 # uncomment to enable diagnostics
 #DEBUG
-# uncomment to use direct usb
+# recommend uncommenting USB_DIRECT and avoid problems
 #USB_DIRECT
 
 # redefine default, use
  K8 XK_KP_3    # Play, or if playing Stop
  K9 XK_End     # End
 
- K10 "["       # Toggle in if no K14
- K11 "]"       # Toggle in if no K15
+ K10 Shift-Ctrl-XK_KP_3 # Loop play between In and Out pointers
+ K11 "l"       # Add label at position
  K12 Ctrl-XK_Left  # Go to previous label
  K13 Ctrl-XK_Right # Go to next label
  K14 "["        # Toggle in