1 /* -*- Mode: C ; c-basic-offset: 2 -*- */
2 /*****************************************************************************
4 * This file is part of jack_mixer
6 * Copyright (C) 2006 Nedko Arnaudov <nedko@arnaudov.name>
7 * Copyright (C) 2009 Frederic Peters <fpeters@0d.be>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
22 *****************************************************************************/
31 #include <jack/jack.h>
32 #if defined(HAVE_JACK_MIDI)
33 #include <jack/midiport.h>
40 #include "jack_mixer.h"
41 //#define LOG_LEVEL LOG_LEVEL_DEBUG
44 #include "jack_compat.h"
46 #define VOLUME_TRANSITION_SECONDS 0.01
48 #define PEAK_FRAMES_CHUNK 4800
50 // we don't know how much to allocate, but we don't want to wait with
51 // allocating until we're in the process() callback, so we just take a
52 // fairly big chunk: 4 periods per buffer, 4096 samples per period.
53 // (not sure if the '*4' is needed)
54 #define MAX_BLOCK_SIZE (4 * 4096)
56 #define FLOAT_EXISTS(x) (!((x) - (x)))
60 struct jack_mixer * mixer_ptr;
64 float volume_transition_seconds;
65 unsigned int num_volume_transition_steps;
67 jack_nframes_t volume_idx;
70 jack_nframes_t balance_idx;
73 float volume_left_new;
75 float volume_right_new;
79 jack_port_t * port_left;
80 jack_port_t * port_right;
82 jack_nframes_t peak_frames;
86 jack_default_audio_sample_t * tmp_mixed_frames_left;
87 jack_default_audio_sample_t * tmp_mixed_frames_right;
88 jack_default_audio_sample_t * frames_left;
89 jack_default_audio_sample_t * frames_right;
90 jack_default_audio_sample_t * prefader_frames_left;
91 jack_default_audio_sample_t * prefader_frames_right;
95 int midi_cc_volume_index;
96 int midi_cc_balance_index;
97 int midi_cc_mute_index;
98 int midi_cc_solo_index;
99 bool midi_cc_volume_picked_up;
100 bool midi_cc_balance_picked_up;
102 jack_default_audio_sample_t * left_buffer_ptr;
103 jack_default_audio_sample_t * right_buffer_ptr;
105 bool midi_in_got_events;
106 void (*midi_change_callback) (void*);
107 void *midi_change_callback_data;
108 bool midi_out_has_events;
110 jack_mixer_scale_t midi_scale;
113 struct output_channel {
114 struct channel channel;
115 GSList *soloed_channels;
116 GSList *muted_channels;
117 GSList *prefader_channels;
119 bool system; /* system channel, without any associated UI */
125 pthread_mutex_t mutex;
126 jack_client_t * jack_client;
127 GSList *input_channels_list;
128 GSList *output_channels_list;
129 GSList *soloed_channels;
131 jack_port_t * port_midi_in;
132 jack_port_t * port_midi_out;
133 int last_midi_channel;
134 enum midi_behavior_mode midi_behavior;
136 struct channel* midi_cc_map[128];
139 static jack_mixer_output_channel_t create_output_channel(
141 const char * channel_name,
146 update_channel_buffers(
147 struct channel * channel_ptr,
148 jack_nframes_t nframes);
160 return 20.0 * log10f(value);
167 return powf(10.0, db/20.0);
170 #define channel_ptr ((struct channel *)channel)
174 jack_mixer_channel_t channel)
176 return channel_ptr->name;
181 jack_mixer_channel_t channel,
185 size_t channel_name_size;
189 new_name = strdup(name);
190 if (new_name == NULL)
195 if (channel_ptr->name)
197 free(channel_ptr->name);
200 channel_ptr->name = new_name;
202 if (channel_ptr->stereo)
204 channel_name_size = strlen(name);
205 port_name = malloc(channel_name_size + 3);
206 memcpy(port_name, name, channel_name_size);
208 port_name[channel_name_size] = ' ';
209 port_name[channel_name_size+1] = 'L';
210 port_name[channel_name_size+2] = 0;
212 ret = jack_port_rename(channel_ptr->mixer_ptr->jack_client, channel_ptr->port_left, port_name);
215 /* what could we do here? */
218 port_name[channel_name_size+1] = 'R';
220 ret = jack_port_rename(channel_ptr->mixer_ptr->jack_client, channel_ptr->port_right, port_name);
223 /* what could we do here? */
230 ret = jack_port_rename(channel_ptr->mixer_ptr->jack_client, channel_ptr->port_left, name);
233 /* what could we do here? */
240 jack_mixer_channel_t channel)
242 return channel_ptr->stereo;
246 channel_get_balance_midi_cc(
247 jack_mixer_channel_t channel)
249 return channel_ptr->midi_cc_balance_index;
253 channel_unset_midi_cc_map(
254 jack_mixer_channel_t channel,
256 if (channel_ptr->mixer_ptr->midi_cc_map[new_cc]->midi_cc_volume_index == new_cc) {
257 channel_ptr->mixer_ptr->midi_cc_map[new_cc]->midi_cc_volume_index = -1;
258 } else if (channel_ptr->mixer_ptr->midi_cc_map[new_cc]->midi_cc_balance_index == new_cc) {
259 channel_ptr->mixer_ptr->midi_cc_map[new_cc]->midi_cc_balance_index = -1;
260 } else if (channel_ptr->mixer_ptr->midi_cc_map[new_cc]->midi_cc_mute_index == new_cc) {
261 channel_ptr->mixer_ptr->midi_cc_map[new_cc]->midi_cc_mute_index = -1;
262 } else if (channel_ptr->mixer_ptr->midi_cc_map[new_cc]->midi_cc_solo_index == new_cc) {
263 channel_ptr->mixer_ptr->midi_cc_map[new_cc]->midi_cc_solo_index = -1;
268 channel_set_balance_midi_cc(
269 jack_mixer_channel_t channel,
272 if (new_cc < 0 || new_cc > 127) {
273 return 2; /* error: outside limit CC */
275 if (channel_ptr->mixer_ptr->midi_cc_map[new_cc] != NULL) {
276 channel_unset_midi_cc_map(channel, new_cc);
278 if (channel_ptr->midi_cc_balance_index != -1) {
279 channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_balance_index] = NULL;
281 channel_ptr->mixer_ptr->midi_cc_map[new_cc] = channel_ptr;
282 channel_ptr->midi_cc_balance_index = new_cc;
287 channel_get_volume_midi_cc(
288 jack_mixer_channel_t channel)
290 return channel_ptr->midi_cc_volume_index;
294 channel_set_volume_midi_cc(
295 jack_mixer_channel_t channel, int new_cc)
297 if (new_cc< 0 || new_cc > 127) {
298 return 2; /* error: outside limit CC */
300 if (channel_ptr->mixer_ptr->midi_cc_map[new_cc] != NULL) {
301 channel_unset_midi_cc_map(channel, new_cc);
303 if (channel_ptr->midi_cc_volume_index != -1) {
304 channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_volume_index] = NULL;
306 channel_ptr->mixer_ptr->midi_cc_map[new_cc] = channel_ptr;
307 channel_ptr->midi_cc_volume_index = new_cc;
312 channel_get_mute_midi_cc(
313 jack_mixer_channel_t channel)
315 return channel_ptr->midi_cc_mute_index;
319 channel_set_mute_midi_cc(
320 jack_mixer_channel_t channel,
323 if (new_cc < 0 || new_cc > 127) {
324 return 2; /* error: outside limit CC */
326 if (channel_ptr->mixer_ptr->midi_cc_map[new_cc] != NULL) {
327 channel_unset_midi_cc_map(channel, new_cc);
330 if (channel_ptr->midi_cc_mute_index != -1) {
331 channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_mute_index] = NULL;
333 channel_ptr->mixer_ptr->midi_cc_map[new_cc] = channel_ptr;
334 channel_ptr->midi_cc_mute_index = new_cc;
339 channel_get_solo_midi_cc(
340 jack_mixer_channel_t channel)
342 return channel_ptr->midi_cc_solo_index;
345 void channel_set_midi_cc_volume_picked_up(jack_mixer_channel_t channel, bool status)
347 LOG_DEBUG("Setting channel %s volume picked up to %d", channel_ptr->name, status);
348 channel_ptr->midi_cc_volume_picked_up = status;
351 void channel_set_midi_cc_balance_picked_up(jack_mixer_channel_t channel, bool status)
353 LOG_DEBUG("Setting channel %s balance picked up to %d", channel_ptr->name, status);
354 channel_ptr->midi_cc_balance_picked_up = status;
358 channel_set_solo_midi_cc(
359 jack_mixer_channel_t channel,
362 if (new_cc < 0 || new_cc > 127) {
363 return 2; /* error: outside limit CC */
365 if (channel_ptr->mixer_ptr->midi_cc_map[new_cc] != NULL) {
366 channel_unset_midi_cc_map(channel, new_cc);
368 if (channel_ptr->midi_cc_solo_index != -1) {
369 channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_solo_index] = NULL;
371 channel_ptr->mixer_ptr->midi_cc_map[new_cc] = channel_ptr;
372 channel_ptr->midi_cc_solo_index = new_cc;
377 channel_autoset_volume_midi_cc(
378 jack_mixer_channel_t channel)
380 struct jack_mixer *mixer_ptr = channel_ptr->mixer_ptr;
382 for (int i = 11 ; i < 128 ; i++)
384 if (mixer_ptr->midi_cc_map[i] == NULL)
386 mixer_ptr->midi_cc_map[i] = channel_ptr;
387 channel_ptr->midi_cc_volume_index = i;
389 LOG_DEBUG("New channel \"%s\" volume mapped to CC#%i", channel_ptr->name, i);
397 channel_autoset_balance_midi_cc(
398 jack_mixer_channel_t channel)
400 struct jack_mixer *mixer_ptr = channel_ptr->mixer_ptr;
402 for (int i = 11; i < 128 ; i++)
404 if (mixer_ptr->midi_cc_map[i] == NULL)
406 mixer_ptr->midi_cc_map[i] = channel_ptr;
407 channel_ptr->midi_cc_balance_index = i;
409 LOG_DEBUG("New channel \"%s\" balance mapped to CC#%i", channel_ptr->name, i);
417 channel_autoset_mute_midi_cc(
418 jack_mixer_channel_t channel)
420 struct jack_mixer *mixer_ptr = channel_ptr->mixer_ptr;
422 for (int i = 11; i < 128 ; i++)
424 if (mixer_ptr->midi_cc_map[i] == NULL)
426 mixer_ptr->midi_cc_map[i] = channel_ptr;
427 channel_ptr->midi_cc_mute_index = i;
429 LOG_DEBUG("New channel \"%s\" mute mapped to CC#%i", channel_ptr->name, i);
437 channel_autoset_solo_midi_cc(
438 jack_mixer_channel_t channel)
440 struct jack_mixer *mixer_ptr = channel_ptr->mixer_ptr;
442 for (int i = 11; i < 128 ; i++)
444 if (mixer_ptr->midi_cc_map[i] == NULL)
446 mixer_ptr->midi_cc_map[i] = channel_ptr;
447 channel_ptr->midi_cc_solo_index = i;
449 LOG_DEBUG("New channel \"%s\" solo mapped to CC#%i", channel_ptr->name, i);
458 jack_mixer_channel_t channel)
461 channel_ptr->mixer_ptr->input_channels_list = g_slist_remove(
462 channel_ptr->mixer_ptr->input_channels_list, channel_ptr);
463 free(channel_ptr->name);
465 /* remove references to input channel from all output channels */
466 for (list_ptr = channel_ptr->mixer_ptr->output_channels_list; list_ptr; list_ptr = g_slist_next(list_ptr))
468 struct output_channel *output_channel_ptr = list_ptr->data;
469 output_channel_set_solo(output_channel_ptr, channel, false);
470 output_channel_set_muted(output_channel_ptr, channel, false);
473 jack_port_unregister(channel_ptr->mixer_ptr->jack_client, channel_ptr->port_left);
474 if (channel_ptr->stereo)
476 jack_port_unregister(channel_ptr->mixer_ptr->jack_client, channel_ptr->port_right);
479 if (channel_ptr->midi_cc_volume_index != -1)
481 assert(channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_volume_index] == channel_ptr);
482 channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_volume_index] = NULL;
485 if (channel_ptr->midi_cc_balance_index != -1)
487 assert(channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_balance_index] == channel_ptr);
488 channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_balance_index] = NULL;
491 if (channel_ptr->midi_cc_mute_index != -1)
493 assert(channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_mute_index] == channel_ptr);
494 channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_mute_index] = NULL;
496 if (channel_ptr->midi_cc_solo_index != -1)
498 assert(channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_solo_index] == channel_ptr);
499 channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_solo_index] = NULL;
502 free(channel_ptr->frames_left);
503 free(channel_ptr->frames_right);
504 free(channel_ptr->prefader_frames_left);
505 free(channel_ptr->prefader_frames_right);
511 channel_stereo_meter_read(
512 jack_mixer_channel_t channel,
517 *left_ptr = value_to_db(channel_ptr->meter_left);
518 *right_ptr = value_to_db(channel_ptr->meter_right);
522 channel_mono_meter_read(
523 jack_mixer_channel_t channel,
526 *mono_ptr = value_to_db(channel_ptr->meter_left);
530 channel_volume_write(
531 jack_mixer_channel_t channel,
535 /*If changing volume and find we're in the middle of a previous transition,
536 *then set current volume to place in transition to avoid a jump.*/
537 if (channel_ptr->volume_new != channel_ptr->volume) {
538 channel_ptr->volume = channel_ptr->volume + channel_ptr->volume_idx *
539 (channel_ptr->volume_new - channel_ptr->volume) /
540 channel_ptr->num_volume_transition_steps;
542 channel_ptr->volume_idx = 0;
543 channel_ptr->volume_new = db_to_value(volume);
544 channel_ptr->midi_out_has_events = true;
549 jack_mixer_channel_t channel)
552 return value_to_db(channel_ptr->volume_new);
556 channels_volumes_read(jack_mixer_t mixer_ptr)
559 struct channel *pChannel;
560 struct jack_mixer * pMixer = (struct jack_mixer *)mixer_ptr;
562 for (node_ptr = pMixer->input_channels_list; node_ptr; node_ptr = g_slist_next(node_ptr))
564 pChannel = (struct channel *)node_ptr->data;
565 double vol = channel_volume_read( (jack_mixer_channel_t)pChannel);
566 printf("%s : volume is %f dbFS for mixer channel: %s\n", jack_get_client_name(pMixer->jack_client), vol, pChannel->name);
571 channel_balance_write(
572 jack_mixer_channel_t channel,
576 if (channel_ptr->balance != channel_ptr->balance_new) {
577 channel_ptr->balance = channel_ptr->balance + channel_ptr->balance_idx *
578 (channel_ptr->balance_new - channel_ptr->balance) /
579 channel_ptr->num_volume_transition_steps;
581 channel_ptr->balance_idx = 0;
582 channel_ptr->balance_new = balance;
586 channel_balance_read(
587 jack_mixer_channel_t channel)
590 return channel_ptr->balance_new;
594 channel_abspeak_read(
595 jack_mixer_channel_t channel)
598 if (channel_ptr->NaN_detected)
604 return value_to_db(channel_ptr->abspeak);
609 channel_abspeak_reset(
610 jack_mixer_channel_t channel)
612 channel_ptr->abspeak = 0;
613 channel_ptr->NaN_detected = false;
618 jack_mixer_channel_t channel)
620 channel_ptr->out_mute = true;
625 jack_mixer_channel_t channel)
627 channel_ptr->out_mute = false;
631 channel_is_out_muted(
632 jack_mixer_channel_t channel)
634 return channel_ptr->out_mute;
639 jack_mixer_channel_t channel)
641 if (g_slist_find(channel_ptr->mixer_ptr->soloed_channels, channel) != NULL)
643 channel_ptr->mixer_ptr->soloed_channels = g_slist_prepend(channel_ptr->mixer_ptr->soloed_channels, channel);
648 jack_mixer_channel_t channel)
650 if (g_slist_find(channel_ptr->mixer_ptr->soloed_channels, channel) == NULL)
652 channel_ptr->mixer_ptr->soloed_channels = g_slist_remove(channel_ptr->mixer_ptr->soloed_channels, channel);
657 jack_mixer_channel_t channel)
659 if (g_slist_find(channel_ptr->mixer_ptr->soloed_channels, channel))
665 channel_set_midi_scale(
666 jack_mixer_channel_t channel,
667 jack_mixer_scale_t scale)
669 channel_ptr->midi_scale = scale;
673 channel_set_midi_change_callback(
674 jack_mixer_channel_t channel,
675 void (*midi_change_callback) (void*),
678 channel_ptr->midi_change_callback = midi_change_callback;
679 channel_ptr->midi_change_callback_data = user_data;
683 channel_get_midi_in_got_events(
684 jack_mixer_channel_t channel)
686 bool t = channel_ptr->midi_in_got_events;
687 channel_ptr->midi_in_got_events = false;
693 /* process input channels and mix them into main mix */
696 struct output_channel *output_mix_channel,
697 GSList *channels_list,
698 jack_nframes_t start, /* index of first sample to process */
699 jack_nframes_t end) /* index of sample to stop processing before */
703 struct channel * channel_ptr;
704 jack_default_audio_sample_t frame_left;
705 jack_default_audio_sample_t frame_right;
706 struct channel *mix_channel = (struct channel*)output_mix_channel;
708 for (i = start; i < end; i++)
710 mix_channel->left_buffer_ptr[i] = mix_channel->tmp_mixed_frames_left[i] = 0.0;
711 if (mix_channel->stereo)
712 mix_channel->right_buffer_ptr[i] = mix_channel->tmp_mixed_frames_right[i] = 0.0;
715 for (node_ptr = channels_list; node_ptr; node_ptr = g_slist_next(node_ptr))
717 channel_ptr = node_ptr->data;
719 if (g_slist_find(output_mix_channel->muted_channels, channel_ptr) != NULL || channel_ptr->out_mute) {
720 /* skip muted channels */
724 if ((!channel_ptr->mixer_ptr->soloed_channels && !output_mix_channel->soloed_channels) ||
725 (channel_ptr->mixer_ptr->soloed_channels &&
726 g_slist_find(channel_ptr->mixer_ptr->soloed_channels, channel_ptr) != NULL) ||
727 (output_mix_channel->soloed_channels &&
728 g_slist_find(output_mix_channel->soloed_channels, channel_ptr) != NULL)) {
730 for (i = start ; i < end ; i++)
732 if (! output_mix_channel->prefader &&
733 g_slist_find(output_mix_channel->prefader_channels, channel_ptr) == NULL) {
734 frame_left = channel_ptr->frames_left[i-start];
736 frame_left = channel_ptr->prefader_frames_left[i-start];
738 if (frame_left == NAN)
740 mix_channel->tmp_mixed_frames_left[i] += frame_left;
741 if (mix_channel->stereo)
743 if (! output_mix_channel->prefader &&
744 g_slist_find(output_mix_channel->prefader_channels, channel_ptr) == NULL) {
745 frame_right = channel_ptr->frames_right[i-start];
747 frame_right = channel_ptr->prefader_frames_right[i-start];
749 if (frame_right == NAN)
751 mix_channel->tmp_mixed_frames_right[i] += frame_right;
757 /* process main mix channel */
758 unsigned int steps = mix_channel->num_volume_transition_steps;
759 for (i = start ; i < end ; i++)
761 if (! output_mix_channel->prefader) {
762 float volume = mix_channel->volume;
763 float volume_new = mix_channel->volume_new;
765 float balance = mix_channel->balance;
766 float balance_new = mix_channel->balance_new;
768 if (volume != volume_new) {
769 vol = mix_channel->volume_idx * (volume_new - volume) / steps + volume;
771 if (balance != balance_new) {
772 bal = mix_channel->balance_idx * (balance_new - balance) / steps + balance;
777 if (mix_channel->stereo) {
779 vol_l = vol * (1 - bal);
783 vol_r = vol * (1 + bal);
786 vol_l = vol * (1 - bal);
787 vol_r = vol * (1 + bal);
789 mix_channel->tmp_mixed_frames_left[i] *= vol_l;
790 mix_channel->tmp_mixed_frames_right[i] *= vol_r;
793 frame_left = fabsf(mix_channel->tmp_mixed_frames_left[i]);
794 if (mix_channel->peak_left < frame_left)
796 mix_channel->peak_left = frame_left;
798 if (frame_left > mix_channel->abspeak)
800 mix_channel->abspeak = frame_left;
804 if (mix_channel->stereo)
806 frame_right = fabsf(mix_channel->tmp_mixed_frames_right[i]);
807 if (mix_channel->peak_right < frame_right)
809 mix_channel->peak_right = frame_right;
811 if (frame_right > mix_channel->abspeak)
813 mix_channel->abspeak = frame_right;
818 mix_channel->peak_frames++;
819 if (mix_channel->peak_frames >= PEAK_FRAMES_CHUNK)
821 mix_channel->meter_left = mix_channel->peak_left;
822 mix_channel->peak_left = 0.0;
824 if (mix_channel->stereo)
826 mix_channel->meter_right = mix_channel->peak_right;
827 mix_channel->peak_right = 0.0;
830 mix_channel->peak_frames = 0;
832 mix_channel->volume_idx++;
833 if ((mix_channel->volume != mix_channel->volume_new) && (mix_channel->volume_idx == steps)) {
834 mix_channel->volume = mix_channel->volume_new;
835 mix_channel->volume_idx = 0;
837 mix_channel->balance_idx++;
838 if ((mix_channel->balance != mix_channel->balance_new) && (mix_channel->balance_idx == steps)) {
839 mix_channel->balance = mix_channel->balance_new;
840 mix_channel->balance_idx = 0;
843 if (!mix_channel->out_mute) {
844 mix_channel->left_buffer_ptr[i] = mix_channel->tmp_mixed_frames_left[i];
845 if (mix_channel->stereo)
846 mix_channel->right_buffer_ptr[i] = mix_channel->tmp_mixed_frames_right[i];
853 struct channel *channel_ptr,
854 jack_nframes_t start,
858 jack_default_audio_sample_t frame_left = 0.0f;
859 jack_default_audio_sample_t frame_right = 0.0f;
860 unsigned int steps = channel_ptr->num_volume_transition_steps;
861 for (i = start ; i < end ; i++)
863 if (i-start >= MAX_BLOCK_SIZE)
865 fprintf(stderr, "i-start too high: %d - %d\n", i, start);
867 channel_ptr->prefader_frames_left[i-start] = channel_ptr->left_buffer_ptr[i];
868 if (channel_ptr->stereo)
869 channel_ptr->prefader_frames_right[i-start] = channel_ptr->right_buffer_ptr[i];
871 if (!FLOAT_EXISTS(channel_ptr->left_buffer_ptr[i]))
873 channel_ptr->NaN_detected = true;
874 channel_ptr->frames_left[i-start] = NAN;
877 float volume = channel_ptr->volume;
878 float volume_new = channel_ptr->volume_new;
880 float balance = channel_ptr->balance;
881 float balance_new = channel_ptr->balance_new;
883 if (channel_ptr->volume != channel_ptr->volume_new) {
884 vol = channel_ptr->volume_idx * (volume_new - volume) / steps + volume;
886 if (channel_ptr->balance != channel_ptr->balance_new) {
887 bal = channel_ptr->balance_idx * (balance_new - balance) / steps + balance;
891 if (channel_ptr->stereo) {
893 vol_l = vol * (1 - bal);
897 vol_r = vol * (1 + bal);
900 vol_l = vol * (1 - bal);
901 vol_r = vol * (1 + bal);
903 frame_left = channel_ptr->left_buffer_ptr[i] * vol_l;
904 if (channel_ptr->stereo)
906 if (!FLOAT_EXISTS(channel_ptr->right_buffer_ptr[i]))
908 channel_ptr->NaN_detected = true;
909 channel_ptr->frames_right[i-start] = NAN;
913 frame_right = channel_ptr->right_buffer_ptr[i] * vol_r;
916 channel_ptr->frames_left[i-start] = frame_left;
917 channel_ptr->frames_right[i-start] = frame_right;
919 if (channel_ptr->stereo)
921 frame_left = fabsf(frame_left);
922 frame_right = fabsf(frame_right);
924 if (channel_ptr->peak_left < frame_left)
926 channel_ptr->peak_left = frame_left;
928 if (frame_left > channel_ptr->abspeak)
930 channel_ptr->abspeak = frame_left;
934 if (channel_ptr->peak_right < frame_right)
936 channel_ptr->peak_right = frame_right;
938 if (frame_right > channel_ptr->abspeak)
940 channel_ptr->abspeak = frame_right;
946 frame_left = (fabsf(frame_left) + fabsf(frame_right)) / 2;
948 if (channel_ptr->peak_left < frame_left)
950 channel_ptr->peak_left = frame_left;
952 if (frame_left > channel_ptr->abspeak)
954 channel_ptr->abspeak = frame_left;
959 channel_ptr->peak_frames++;
960 if (channel_ptr->peak_frames >= PEAK_FRAMES_CHUNK)
962 channel_ptr->meter_left = channel_ptr->peak_left;
963 channel_ptr->peak_left = 0.0;
965 if (channel_ptr->stereo)
967 channel_ptr->meter_right = channel_ptr->peak_right;
968 channel_ptr->peak_right = 0.0;
971 channel_ptr->peak_frames = 0;
973 channel_ptr->volume_idx++;
974 if ((channel_ptr->volume != channel_ptr->volume_new) &&
975 (channel_ptr->volume_idx == steps)) {
976 channel_ptr->volume = channel_ptr->volume_new;
977 channel_ptr->volume_idx = 0;
979 channel_ptr->balance_idx++;
980 if ((channel_ptr->balance != channel_ptr->balance_new) &&
981 (channel_ptr->balance_idx >= steps)) {
982 channel_ptr->balance = channel_ptr->balance_new;
983 channel_ptr->balance_idx = 0;
990 struct jack_mixer * mixer_ptr,
991 jack_nframes_t start, /* index of first sample to process */
992 jack_nframes_t end) /* index of sample to stop processing before */
995 struct output_channel * output_channel_ptr;
996 struct channel *channel_ptr;
998 for (node_ptr = mixer_ptr->input_channels_list; node_ptr; node_ptr = g_slist_next(node_ptr))
1000 channel_ptr = (struct channel*)node_ptr->data;
1001 calc_channel_frames(channel_ptr, start, end);
1004 for (node_ptr = mixer_ptr->output_channels_list; node_ptr; node_ptr = g_slist_next(node_ptr))
1006 output_channel_ptr = node_ptr->data;
1007 channel_ptr = (struct channel*)output_channel_ptr;
1009 if (output_channel_ptr->system)
1011 /* Don't bother mixing the channels if we are not connected */
1012 if (channel_ptr->stereo)
1014 if (jack_port_connected(channel_ptr->port_left) == 0 &&
1015 jack_port_connected(channel_ptr->port_right) == 0)
1018 if (jack_port_connected(channel_ptr->port_left) == 0)
1023 mix_one(output_channel_ptr, mixer_ptr->input_channels_list, start, end);
1028 update_channel_buffers(
1029 struct channel * channel_ptr,
1030 jack_nframes_t nframes)
1032 channel_ptr->left_buffer_ptr = jack_port_get_buffer(channel_ptr->port_left, nframes);
1034 if (channel_ptr->stereo)
1036 channel_ptr->right_buffer_ptr = jack_port_get_buffer(channel_ptr->port_right, nframes);
1040 #define mixer_ptr ((struct jack_mixer *)context)
1044 jack_nframes_t nframes,
1049 struct channel * channel_ptr;
1050 #if defined(HAVE_JACK_MIDI)
1051 jack_nframes_t event_count;
1052 jack_midi_event_t in_event;
1053 unsigned char* midi_out_buffer;
1056 unsigned int cc_channel_index;
1059 for (node_ptr = mixer_ptr->input_channels_list; node_ptr; node_ptr = g_slist_next(node_ptr))
1061 channel_ptr = node_ptr->data;
1062 update_channel_buffers(channel_ptr, nframes);
1065 // Fill output buffers with the input
1066 for (node_ptr = mixer_ptr->output_channels_list; node_ptr; node_ptr = g_slist_next(node_ptr))
1068 channel_ptr = node_ptr->data;
1069 update_channel_buffers(channel_ptr, nframes);
1072 #if defined(HAVE_JACK_MIDI)
1073 midi_buffer = jack_port_get_buffer(mixer_ptr->port_midi_in, nframes);
1074 event_count = jack_midi_get_event_count(midi_buffer);
1076 for (i = 0 ; i < event_count; i++)
1078 jack_midi_event_get(&in_event, midi_buffer, i);
1080 if (in_event.size != 3 ||
1081 (in_event.buffer[0] & 0xF0) != 0xB0 ||
1082 in_event.buffer[1] > 127 ||
1083 in_event.buffer[2] > 127)
1088 assert(in_event.time < nframes);
1092 (unsigned int)(in_event.buffer[0]),
1093 (unsigned int)in_event.buffer[1],
1094 (unsigned int)in_event.buffer[2]);
1096 mixer_ptr->last_midi_channel = (int)in_event.buffer[1];
1097 channel_ptr = mixer_ptr->midi_cc_map[in_event.buffer[1]];
1099 /* if we have mapping for particular CC and MIDI scale is set for corresponding channel */
1100 if (channel_ptr != NULL && channel_ptr->midi_scale != NULL)
1102 if (channel_ptr->midi_cc_balance_index == (char)in_event.buffer[1])
1104 byte = in_event.buffer[2];
1110 int current_midi = (int)63 * channel_ptr->balance + 64;
1111 current_midi = current_midi == 1 ? 0 : current_midi;
1112 if (mixer_ptr->midi_behavior == Pick_Up &&
1113 !channel_ptr->midi_cc_balance_picked_up) {
1114 if (in_event.buffer[2] == current_midi) {
1115 channel_set_midi_cc_balance_picked_up(channel_ptr, true);
1118 if ((mixer_ptr->midi_behavior == Pick_Up &&
1119 channel_ptr->midi_cc_balance_picked_up) ||
1120 mixer_ptr->midi_behavior == Jump_To_Value) {
1121 if (channel_ptr->balance != channel_ptr->balance_new) {
1122 channel_ptr->balance = channel_ptr->balance + channel_ptr->balance_idx *
1123 (channel_ptr->balance_new - channel_ptr->balance) /
1124 channel_ptr->num_volume_transition_steps;
1126 channel_ptr->balance_idx = 0;
1127 channel_ptr->balance_new = (float)byte / 63;
1128 LOG_DEBUG("\"%s\" balance -> %f", channel_ptr->name, channel_ptr->balance_new);
1131 else if (channel_ptr->midi_cc_volume_index == in_event.buffer[1])
1133 int current_midi = (int)(127 *
1134 scale_db_to_scale(channel_ptr->midi_scale,
1135 value_to_db(channel_ptr->volume)));
1136 if (mixer_ptr->midi_behavior == Pick_Up &&
1137 !channel_ptr->midi_cc_volume_picked_up ) {
1138 if (in_event.buffer[2] == current_midi) {
1139 channel_set_midi_cc_volume_picked_up(channel_ptr, true);
1142 if ((mixer_ptr->midi_behavior == Pick_Up &&
1143 channel_ptr->midi_cc_volume_picked_up) ||
1144 mixer_ptr->midi_behavior == Jump_To_Value) {
1145 if (channel_ptr->volume_new != channel_ptr->volume) {
1146 channel_ptr->volume = channel_ptr->volume + channel_ptr->volume_idx *
1147 (channel_ptr->volume_new - channel_ptr->volume) /
1148 channel_ptr->num_volume_transition_steps;
1150 channel_ptr->volume_idx = 0;
1151 channel_ptr->volume_new = db_to_value(scale_scale_to_db(channel_ptr->midi_scale,
1152 (double)in_event.buffer[2] / 127));
1153 LOG_DEBUG("\"%s\" volume -> %f", channel_ptr->name, channel_ptr->volume_new);
1156 else if (channel_ptr->midi_cc_mute_index == in_event.buffer[1])
1158 if ((unsigned int)in_event.buffer[2] == 127) {
1159 channel_ptr->out_mute = !channel_ptr->out_mute;
1161 LOG_DEBUG("\"%s\" out_mute %d", channel_ptr->name, channel_ptr->out_mute);
1163 else if (channel_ptr->midi_cc_solo_index == in_event.buffer[1])
1165 if ((unsigned int)in_event.buffer[2] == 127) {
1166 if (channel_is_soloed(channel_ptr)) {
1167 channel_unsolo(channel_ptr);
1169 channel_solo(channel_ptr);
1172 LOG_DEBUG("\"%s\" solo %d", channel_ptr->name, channel_is_soloed(channel_ptr));
1174 channel_ptr->midi_in_got_events = true;
1175 if (channel_ptr->midi_change_callback)
1176 channel_ptr->midi_change_callback(channel_ptr->midi_change_callback_data);
1182 midi_buffer = jack_port_get_buffer(mixer_ptr->port_midi_out, nframes);
1183 jack_midi_clear_buffer(midi_buffer);
1185 for(i=0; i<nframes; i++)
1187 for (cc_channel_index=0; cc_channel_index<128; cc_channel_index++)
1189 channel_ptr = mixer_ptr->midi_cc_map[cc_channel_index];
1190 if (channel_ptr == NULL || channel_ptr->midi_scale == NULL)
1194 if (channel_ptr->midi_out_has_events == false)
1198 if (channel_ptr->midi_cc_balance_index == (int)cc_channel_index)
1202 midi_out_buffer = jack_midi_event_reserve(midi_buffer, i, 3);
1203 if (midi_out_buffer == NULL)
1207 midi_out_buffer[0] = 0xB0; /* control change */
1208 midi_out_buffer[1] = cc_channel_index;
1209 midi_out_buffer[2] = (unsigned char)(127*scale_db_to_scale(channel_ptr->midi_scale, value_to_db(channel_ptr->volume_new)));
1213 (unsigned int)(midi_out_buffer[0]),
1214 (unsigned int)midi_out_buffer[1],
1215 (unsigned int)midi_out_buffer[2]);
1217 channel_ptr->midi_out_has_events = false;
1223 mix(mixer_ptr, 0, nframes);
1232 const char * jack_client_name_ptr,
1237 struct jack_mixer * mixer_ptr;
1241 mixer_ptr = malloc(sizeof(struct jack_mixer));
1242 if (mixer_ptr == NULL)
1247 ret = pthread_mutex_init(&mixer_ptr->mutex, NULL);
1253 mixer_ptr->input_channels_list = NULL;
1254 mixer_ptr->output_channels_list = NULL;
1256 mixer_ptr->soloed_channels = NULL;
1258 mixer_ptr->last_midi_channel = -1;
1260 mixer_ptr->midi_behavior = Jump_To_Value;
1262 for (i = 0 ; i < 128 ; i++)
1264 mixer_ptr->midi_cc_map[i] = NULL;
1267 LOG_DEBUG("Initializing JACK");
1268 mixer_ptr->jack_client = jack_client_open(jack_client_name_ptr, 0, NULL);
1269 if (mixer_ptr->jack_client == NULL)
1271 LOG_ERROR("Cannot create JACK client.");
1272 LOG_NOTICE("Please make sure JACK daemon is running.");
1273 goto exit_destroy_mutex;
1276 LOG_DEBUG("JACK client created");
1278 LOG_DEBUG("Sample rate: %" PRIu32, jack_get_sample_rate(mixer_ptr->jack_client));
1281 #if defined(HAVE_JACK_MIDI)
1282 mixer_ptr->port_midi_in = jack_port_register(mixer_ptr->jack_client, "midi in", JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, 0);
1283 if (mixer_ptr->port_midi_in == NULL)
1285 LOG_ERROR("Cannot create JACK MIDI in port");
1289 mixer_ptr->port_midi_out = jack_port_register(mixer_ptr->jack_client, "midi out", JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0);
1290 if (mixer_ptr->port_midi_out == NULL)
1292 LOG_ERROR("Cannot create JACK MIDI out port");
1298 ret = jack_set_process_callback(mixer_ptr->jack_client, process, mixer_ptr);
1301 LOG_ERROR("Cannot set JACK process callback");
1305 ret = jack_activate(mixer_ptr->jack_client);
1308 LOG_ERROR("Cannot activate JACK client");
1315 jack_client_close(mixer_ptr->jack_client); /* this should clear all other resources we obtained through the client handle */
1318 pthread_mutex_destroy(&mixer_ptr->mutex);
1327 #define mixer_ctx_ptr ((struct jack_mixer *)mixer)
1333 LOG_DEBUG("Uninitializing JACK");
1335 assert(mixer_ctx_ptr->jack_client != NULL);
1337 jack_client_close(mixer_ctx_ptr->jack_client);
1339 pthread_mutex_destroy(&mixer_ctx_ptr->mutex);
1341 free(mixer_ctx_ptr);
1349 return g_slist_length(mixer_ctx_ptr->input_channels_list);
1356 return jack_get_client_name(mixer_ctx_ptr->jack_client);
1360 get_last_midi_channel(
1363 return mixer_ctx_ptr->last_midi_channel;
1367 set_last_midi_channel(
1370 mixer_ctx_ptr->last_midi_channel = new_channel;
1375 get_midi_behavior_mode(
1378 return mixer_ctx_ptr->midi_behavior;
1382 set_midi_behavior_mode(
1384 enum midi_behavior_mode mode)
1386 mixer_ctx_ptr->midi_behavior = mode;
1390 jack_mixer_channel_t
1393 const char * channel_name,
1396 struct channel * channel_ptr;
1397 char * port_name = NULL;
1398 size_t channel_name_size;
1400 channel_ptr = malloc(sizeof(struct channel));
1401 if (channel_ptr == NULL)
1406 channel_ptr->mixer_ptr = mixer_ctx_ptr;
1408 channel_ptr->name = strdup(channel_name);
1409 if (channel_ptr->name == NULL)
1411 goto fail_free_channel;
1414 channel_name_size = strlen(channel_name);
1418 port_name = malloc(channel_name_size + 3);
1419 if (port_name == NULL)
1421 goto fail_free_channel_name;
1424 memcpy(port_name, channel_name, channel_name_size);
1425 port_name[channel_name_size] = ' ';
1426 port_name[channel_name_size+1] = 'L';
1427 port_name[channel_name_size+2] = 0;
1429 channel_ptr->port_left = jack_port_register(channel_ptr->mixer_ptr->jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
1430 if (channel_ptr->port_left == NULL)
1432 goto fail_free_port_name;
1435 port_name[channel_name_size+1] = 'R';
1437 channel_ptr->port_right = jack_port_register(channel_ptr->mixer_ptr->jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
1438 if (channel_ptr->port_right == NULL)
1440 goto fail_unregister_left_channel;
1445 channel_ptr->port_left = jack_port_register(channel_ptr->mixer_ptr->jack_client, channel_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
1446 if (channel_ptr->port_left == NULL)
1448 goto fail_free_channel_name;
1452 channel_ptr->stereo = stereo;
1454 channel_ptr->volume_transition_seconds = VOLUME_TRANSITION_SECONDS;
1455 channel_ptr->num_volume_transition_steps =
1456 channel_ptr->volume_transition_seconds *
1457 jack_get_sample_rate(channel_ptr->mixer_ptr->jack_client) + 1;
1458 channel_ptr->volume = 0.0;
1459 channel_ptr->volume_new = 0.0;
1460 channel_ptr->balance = 0.0;
1461 channel_ptr->balance_new = 0.0;
1462 channel_ptr->meter_left = -1.0;
1463 channel_ptr->meter_right = -1.0;
1464 channel_ptr->abspeak = 0.0;
1465 channel_ptr->out_mute = false;
1467 channel_ptr->peak_left = 0.0;
1468 channel_ptr->peak_right = 0.0;
1469 channel_ptr->peak_frames = 0;
1471 channel_ptr->frames_left = calloc(MAX_BLOCK_SIZE, sizeof(jack_default_audio_sample_t));
1472 channel_ptr->frames_right = calloc(MAX_BLOCK_SIZE, sizeof(jack_default_audio_sample_t));
1473 channel_ptr->prefader_frames_left = calloc(MAX_BLOCK_SIZE, sizeof(jack_default_audio_sample_t));
1474 channel_ptr->prefader_frames_right = calloc(MAX_BLOCK_SIZE, sizeof(jack_default_audio_sample_t));
1476 channel_ptr->NaN_detected = false;
1478 channel_ptr->midi_cc_volume_index = -1;
1479 channel_ptr->midi_cc_balance_index = -1;
1480 channel_ptr->midi_cc_mute_index = -1;
1481 channel_ptr->midi_cc_solo_index = -1;
1482 channel_ptr->midi_cc_volume_picked_up = false;
1483 channel_ptr->midi_cc_balance_picked_up = false;
1485 channel_ptr->midi_change_callback = NULL;
1486 channel_ptr->midi_change_callback_data = NULL;
1487 channel_ptr->midi_out_has_events = false;
1489 channel_ptr->midi_scale = NULL;
1491 channel_ptr->mixer_ptr->input_channels_list = g_slist_prepend(
1492 channel_ptr->mixer_ptr->input_channels_list, channel_ptr);
1497 fail_unregister_left_channel:
1498 jack_port_unregister(channel_ptr->mixer_ptr->jack_client, channel_ptr->port_left);
1500 fail_free_port_name:
1503 fail_free_channel_name:
1504 free(channel_ptr->name);
1514 static jack_mixer_output_channel_t
1515 create_output_channel(
1517 const char * channel_name,
1521 struct channel * channel_ptr;
1522 struct output_channel * output_channel_ptr;
1523 char * port_name = NULL;
1524 size_t channel_name_size;
1526 output_channel_ptr = malloc(sizeof(struct output_channel));
1527 channel_ptr = (struct channel*)output_channel_ptr;
1528 if (channel_ptr == NULL)
1533 channel_ptr->mixer_ptr = mixer_ctx_ptr;
1535 channel_ptr->name = strdup(channel_name);
1536 if (channel_ptr->name == NULL)
1538 goto fail_free_channel;
1543 channel_name_size = strlen(channel_name);
1545 port_name = malloc(channel_name_size + 4);
1546 if (port_name == NULL)
1548 goto fail_free_channel_name;
1551 memcpy(port_name, channel_name, channel_name_size);
1552 port_name[channel_name_size] = ' ';
1553 port_name[channel_name_size+1] = 'L';
1554 port_name[channel_name_size+2] = 0;
1556 channel_ptr->port_left = jack_port_register(channel_ptr->mixer_ptr->jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
1557 if (channel_ptr->port_left == NULL)
1559 goto fail_free_port_name;
1562 port_name[channel_name_size+1] = 'R';
1564 channel_ptr->port_right = jack_port_register(channel_ptr->mixer_ptr->jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
1565 if (channel_ptr->port_right == NULL)
1567 goto fail_unregister_left_channel;
1572 channel_ptr->port_left = jack_port_register(channel_ptr->mixer_ptr->jack_client, channel_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
1573 if (channel_ptr->port_left == NULL)
1575 goto fail_free_channel_name;
1579 channel_ptr->stereo = stereo;
1580 channel_ptr->out_mute = false;
1582 channel_ptr->volume_transition_seconds = VOLUME_TRANSITION_SECONDS;
1583 channel_ptr->num_volume_transition_steps =
1584 channel_ptr->volume_transition_seconds *
1585 jack_get_sample_rate(channel_ptr->mixer_ptr->jack_client) + 1;
1586 channel_ptr->volume = 0.0;
1587 channel_ptr->volume_new = 0.0;
1588 channel_ptr->balance = 0.0;
1589 channel_ptr->balance_new = 0.0;
1590 channel_ptr->meter_left = -1.0;
1591 channel_ptr->meter_right = -1.0;
1592 channel_ptr->abspeak = 0.0;
1594 channel_ptr->peak_left = 0.0;
1595 channel_ptr->peak_right = 0.0;
1596 channel_ptr->peak_frames = 0;
1598 channel_ptr->tmp_mixed_frames_left = calloc(MAX_BLOCK_SIZE, sizeof(jack_default_audio_sample_t));
1599 channel_ptr->tmp_mixed_frames_right = calloc(MAX_BLOCK_SIZE, sizeof(jack_default_audio_sample_t));
1600 channel_ptr->frames_left = calloc(MAX_BLOCK_SIZE, sizeof(jack_default_audio_sample_t));
1601 channel_ptr->frames_right = calloc(MAX_BLOCK_SIZE, sizeof(jack_default_audio_sample_t));
1602 channel_ptr->prefader_frames_left = calloc(MAX_BLOCK_SIZE, sizeof(jack_default_audio_sample_t));
1603 channel_ptr->prefader_frames_right = calloc(MAX_BLOCK_SIZE, sizeof(jack_default_audio_sample_t));
1605 channel_ptr->NaN_detected = false;
1607 channel_ptr->midi_cc_volume_index = -1;
1608 channel_ptr->midi_cc_balance_index = -1;
1609 channel_ptr->midi_cc_mute_index = -1;
1610 channel_ptr->midi_cc_solo_index = -1;
1611 channel_ptr->midi_cc_volume_picked_up = false;
1612 channel_ptr->midi_cc_balance_picked_up = false;
1614 channel_ptr->midi_change_callback = NULL;
1615 channel_ptr->midi_change_callback_data = NULL;
1617 channel_ptr->midi_scale = NULL;
1619 output_channel_ptr->soloed_channels = NULL;
1620 output_channel_ptr->muted_channels = NULL;
1621 output_channel_ptr->prefader_channels = NULL;
1622 output_channel_ptr->system = system;
1623 output_channel_ptr->prefader = false;
1626 return output_channel_ptr;
1628 fail_unregister_left_channel:
1629 jack_port_unregister(channel_ptr->mixer_ptr->jack_client, channel_ptr->port_left);
1631 fail_free_port_name:
1634 fail_free_channel_name:
1635 free(channel_ptr->name);
1645 jack_mixer_output_channel_t
1648 const char * channel_name,
1652 struct output_channel *output_channel_ptr;
1653 struct channel *channel_ptr;
1655 output_channel_ptr = create_output_channel(mixer, channel_name, stereo, system);
1656 if (output_channel_ptr == NULL) {
1659 channel_ptr = (struct channel*)output_channel_ptr;
1661 ((struct jack_mixer*)mixer)->output_channels_list = g_slist_prepend(
1662 ((struct jack_mixer*)mixer)->output_channels_list, channel_ptr);
1664 return output_channel_ptr;
1672 for (list_ptr = mixer_ctx_ptr->input_channels_list; list_ptr; list_ptr = g_slist_next(list_ptr))
1674 struct channel *input_channel_ptr = list_ptr->data;
1675 remove_channel((jack_mixer_channel_t)input_channel_ptr);
1680 remove_output_channel(
1681 jack_mixer_output_channel_t output_channel)
1683 struct output_channel *output_channel_ptr = output_channel;
1684 struct channel *channel_ptr = output_channel;
1686 channel_ptr->mixer_ptr->output_channels_list = g_slist_remove(
1687 channel_ptr->mixer_ptr->output_channels_list, channel_ptr);
1688 free(channel_ptr->name);
1690 jack_port_unregister(channel_ptr->mixer_ptr->jack_client, channel_ptr->port_left);
1691 if (channel_ptr->stereo)
1693 jack_port_unregister(channel_ptr->mixer_ptr->jack_client, channel_ptr->port_right);
1696 if (channel_ptr->midi_cc_volume_index != -1)
1698 assert(channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_volume_index] == channel_ptr);
1699 channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_volume_index] = NULL;
1702 if (channel_ptr->midi_cc_balance_index != -1)
1704 assert(channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_balance_index] == channel_ptr);
1705 channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_balance_index] = NULL;
1708 if (channel_ptr->midi_cc_mute_index != -1)
1710 assert(channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_mute_index] == channel_ptr);
1711 channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_mute_index] = NULL;
1714 if (channel_ptr->midi_cc_solo_index != -1)
1716 assert(channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_solo_index] == channel_ptr);
1717 channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_solo_index] = NULL;
1720 g_slist_free(output_channel_ptr->soloed_channels);
1721 g_slist_free(output_channel_ptr->muted_channels);
1722 g_slist_free(output_channel_ptr->prefader_channels);
1724 free(channel_ptr->tmp_mixed_frames_left);
1725 free(channel_ptr->tmp_mixed_frames_right);
1726 free(channel_ptr->frames_left);
1727 free(channel_ptr->frames_right);
1728 free(channel_ptr->prefader_frames_left);
1729 free(channel_ptr->prefader_frames_right);
1735 output_channel_set_solo(
1736 jack_mixer_output_channel_t output_channel,
1737 jack_mixer_channel_t channel,
1740 struct output_channel *output_channel_ptr = output_channel;
1743 if (g_slist_find(output_channel_ptr->soloed_channels, channel) != NULL)
1745 output_channel_ptr->soloed_channels = g_slist_prepend(output_channel_ptr->soloed_channels, channel);
1747 if (g_slist_find(output_channel_ptr->soloed_channels, channel) == NULL)
1749 output_channel_ptr->soloed_channels = g_slist_remove(output_channel_ptr->soloed_channels, channel);
1754 output_channel_set_muted(
1755 jack_mixer_output_channel_t output_channel,
1756 jack_mixer_channel_t channel,
1759 struct output_channel *output_channel_ptr = output_channel;
1762 if (g_slist_find(output_channel_ptr->muted_channels, channel) != NULL)
1764 output_channel_ptr->muted_channels = g_slist_prepend(output_channel_ptr->muted_channels, channel);
1766 if (g_slist_find(output_channel_ptr->muted_channels, channel) == NULL)
1768 output_channel_ptr->muted_channels = g_slist_remove(output_channel_ptr->muted_channels, channel);
1773 output_channel_is_muted(
1774 jack_mixer_output_channel_t output_channel,
1775 jack_mixer_channel_t channel)
1777 struct output_channel *output_channel_ptr = output_channel;
1779 if (g_slist_find(output_channel_ptr->muted_channels, channel) != NULL)
1785 output_channel_is_solo(
1786 jack_mixer_output_channel_t output_channel,
1787 jack_mixer_channel_t channel)
1789 struct output_channel *output_channel_ptr = output_channel;
1791 if (g_slist_find(output_channel_ptr->soloed_channels, channel) != NULL)
1797 output_channel_set_prefader(
1798 jack_mixer_output_channel_t output_channel,
1801 struct output_channel *output_channel_ptr = output_channel;
1802 output_channel_ptr->prefader = pfl_value;
1806 output_channel_is_prefader(
1807 jack_mixer_output_channel_t output_channel)
1809 struct output_channel *output_channel_ptr = output_channel;
1810 return output_channel_ptr->prefader;
1814 output_channel_set_in_prefader(
1815 jack_mixer_output_channel_t output_channel,
1816 jack_mixer_channel_t channel,
1817 bool prefader_value)
1819 struct output_channel *output_channel_ptr = output_channel;
1821 if (prefader_value) {
1822 if (g_slist_find(output_channel_ptr->prefader_channels, channel) != NULL)
1824 output_channel_ptr->prefader_channels = g_slist_prepend(output_channel_ptr->prefader_channels, channel);
1826 if (g_slist_find(output_channel_ptr->prefader_channels, channel) == NULL)
1828 output_channel_ptr->prefader_channels = g_slist_remove(output_channel_ptr->prefader_channels, channel);
1833 output_channel_is_in_prefader(
1834 jack_mixer_output_channel_t output_channel,
1835 jack_mixer_channel_t channel)
1837 struct output_channel *output_channel_ptr = output_channel;
1839 if (g_slist_find(output_channel_ptr->prefader_channels, channel) != NULL)