Consolidate ctrl surface code
authorRobin Gareus <robin@gareus.org>
Fri, 4 Aug 2017 23:27:41 +0000 (01:27 +0200)
committerRobin Gareus <robin@gareus.org>
Fri, 4 Aug 2017 23:28:11 +0000 (01:28 +0200)
libs/ardour/midi_ui.cc
libs/surfaces/cc121/cc121.cc
libs/surfaces/faderport/faderport.cc
libs/surfaces/faderport8/faderport8.cc
libs/surfaces/mackie/mackie_control_protocol.cc
libs/surfaces/push2/push2.cc
libs/surfaces/tranzport/init.cc

index eaacde2969f3cb5cc077f8d5ee383610154f8570..11ab77a851a1c85e1f04d0805735f0bbd9e99f9d 100644 (file)
@@ -144,19 +144,12 @@ MidiControlUI::reset_ports ()
 void
 MidiControlUI::thread_init ()
 {
-       struct sched_param rtparam;
-
        pthread_set_name (X_("midiUI"));
 
        PBD::notify_event_loops_about_thread_creation (pthread_self(), X_("midiUI"), 2048);
        SessionEvent::create_per_thread_pool (X_("midiUI"), 128);
 
-       memset (&rtparam, 0, sizeof (rtparam));
-       rtparam.sched_priority = 9; /* XXX should be relative to audio (JACK) thread */
-
-       if (pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam) != 0) {
-               // do we care? not particularly.
-       }
+       set_thread_priority ();
 
        reset_ports ();
 }
index b00fbbb54150cb743cc2f5c4739db2114058774d..8a8cfb6597d443d4f3c837be9c38d2216c92cd85 100644 (file)
@@ -268,19 +268,12 @@ CC121::stop ()
 void
 CC121::thread_init ()
 {
-       struct sched_param rtparam;
-
        pthread_set_name (event_loop_name().c_str());
 
        PBD::notify_event_loops_about_thread_creation (pthread_self(), event_loop_name(), 2048);
        ARDOUR::SessionEvent::create_per_thread_pool (event_loop_name(), 128);
 
-       memset (&rtparam, 0, sizeof (rtparam));
-       rtparam.sched_priority = 9; /* XXX should be relative to audio (JACK) thread */
-
-       if (pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam) != 0) {
-               // do we care? not particularly.
-       }
+       set_thread_priority ();
 }
 
 void
index 4984c73b06a01acc79295aef4bbd45a74d157b28..72190c1e8a0370970723688de1d5f832d41ae39c 100644 (file)
@@ -286,19 +286,12 @@ FaderPort::stop ()
 void
 FaderPort::thread_init ()
 {
-       struct sched_param rtparam;
-
        pthread_set_name (event_loop_name().c_str());
 
        PBD::notify_event_loops_about_thread_creation (pthread_self(), event_loop_name(), 2048);
        ARDOUR::SessionEvent::create_per_thread_pool (event_loop_name(), 128);
 
-       memset (&rtparam, 0, sizeof (rtparam));
-       rtparam.sched_priority = 9; /* XXX should be relative to audio (JACK) thread */
-
-       if (pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam) != 0) {
-               // do we care? not particularly.
-       }
+       set_thread_priority ();
 }
 
 void
index 9b355782554b122bf58214a763b64331749d9169..0ba8ae422a23c8536904ecdc99e8d88af7656612 100644 (file)
@@ -210,19 +210,12 @@ FaderPort8::stop ()
 void
 FaderPort8::thread_init ()
 {
-       struct sched_param rtparam;
-
        pthread_set_name (event_loop_name().c_str());
 
        PBD::notify_event_loops_about_thread_creation (pthread_self(), event_loop_name(), 2048);
        ARDOUR::SessionEvent::create_per_thread_pool (event_loop_name(), 128);
 
-       memset (&rtparam, 0, sizeof (rtparam));
-       rtparam.sched_priority = 9; /* XXX should be relative to audio (JACK) thread */
-
-       if (pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam) != 0) {
-               // do we care? not particularly.
-       }
+       set_thread_priority ();
 }
 
 bool
index 3d011c1bb61f2dc6179a75d4291e17d02a836b5e..064d763d1e41ae5184a47e020567d125b60aeb52 100644 (file)
@@ -184,19 +184,12 @@ MackieControlProtocol::~MackieControlProtocol()
 void
 MackieControlProtocol::thread_init ()
 {
-       struct sched_param rtparam;
-
        pthread_set_name (event_loop_name().c_str());
 
        PBD::notify_event_loops_about_thread_creation (pthread_self(), event_loop_name(), 2048);
        ARDOUR::SessionEvent::create_per_thread_pool (event_loop_name(), 128);
 
-       memset (&rtparam, 0, sizeof (rtparam));
-       rtparam.sched_priority = 9; /* XXX should be relative to audio (JACK) thread */
-
-       if (pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam) != 0) {
-               // do we care? not particularly.
-       }
+       set_thread_priority ();
 }
 
 void
index d884869048b985ae56a584823005c87821672429..b14513b30b4dbdccd087b9489058859b6737a4c2 100644 (file)
@@ -849,19 +849,12 @@ Push2::handle_midi_pitchbend_message (MIDI::Parser&, MIDI::pitchbend_t pb)
 void
 Push2::thread_init ()
 {
-       struct sched_param rtparam;
-
        pthread_set_name (event_loop_name().c_str());
 
        PBD::notify_event_loops_about_thread_creation (pthread_self(), event_loop_name(), 2048);
        ARDOUR::SessionEvent::create_per_thread_pool (event_loop_name(), 128);
 
-       memset (&rtparam, 0, sizeof (rtparam));
-       rtparam.sched_priority = 9; /* XXX should be relative to audio (JACK) thread */
-
-       if (pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam) != 0) {
-               // do we care? not particularly.
-       }
+       set_thread_priority ();
 }
 
 void
index 1e284b5831ff8a4d4b7ce6028b8601f3bca1dc05..96ff493c0ef63a39c4ea96a00ad800b7279e057f 100644 (file)
@@ -43,16 +43,12 @@ TranzportControlProtocol::~TranzportControlProtocol ()
 
 int TranzportControlProtocol::rtpriority_set(int priority)
 {
-       struct sched_param rtparam;
-       int err;
        char *a = (char*) alloca(4096*2); a[0] = 'a'; a[4096] = 'b';
-       memset (&rtparam, 0, sizeof (rtparam));
-       rtparam.sched_priority = priority; /* XXX should be relative to audio (JACK) thread */
        // Note - try SCHED_RR with a low limit
        // - we don't care if we can't write everything this ms
        // and it will help if we lose the device
-       if ((err = pthread_setschedparam (pthread_self(), SCHED_FIFO, &rtparam)) != 0) {
-               PBD::info << string_compose (_("%1: thread not running with realtime scheduling (%2)"), name(), strerror (errno)) << endmsg;
+       if (set_thread_priority (SCHED_FIFO, priority)) {
+               PBD::info << string_compose (_("%1: thread not running with realtime scheduling."), name(), strerror (errno)) << endmsg;
                return 1;
        }
        return 0;