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 bool system; /* system channel, without any associated UI */
123 pthread_mutex_t mutex;
124 jack_client_t * jack_client;
125 GSList *input_channels_list;
126 GSList *output_channels_list;
127 GSList *soloed_channels;
129 jack_port_t * port_midi_in;
130 jack_port_t * port_midi_out;
131 int last_midi_channel;
132 enum midi_behavior_mode midi_behavior;
134 struct channel* midi_cc_map[128];
137 static jack_mixer_output_channel_t create_output_channel(
139 const char * channel_name,
144 update_channel_buffers(
145 struct channel * channel_ptr,
146 jack_nframes_t nframes);
158 return 20.0 * log10f(value);
165 return powf(10.0, db/20.0);
168 #define channel_ptr ((struct channel *)channel)
172 jack_mixer_channel_t channel)
174 return channel_ptr->name;
179 jack_mixer_channel_t channel,
183 size_t channel_name_size;
187 new_name = strdup(name);
188 if (new_name == NULL)
193 if (channel_ptr->name)
195 free(channel_ptr->name);
198 channel_ptr->name = new_name;
200 if (channel_ptr->stereo)
202 channel_name_size = strlen(name);
203 port_name = malloc(channel_name_size + 3);
204 memcpy(port_name, name, channel_name_size);
206 port_name[channel_name_size] = ' ';
207 port_name[channel_name_size+1] = 'L';
208 port_name[channel_name_size+2] = 0;
210 ret = jack_port_rename(channel_ptr->mixer_ptr->jack_client, channel_ptr->port_left, port_name);
213 /* what could we do here? */
216 port_name[channel_name_size+1] = 'R';
218 ret = jack_port_rename(channel_ptr->mixer_ptr->jack_client, channel_ptr->port_right, port_name);
221 /* what could we do here? */
228 ret = jack_port_rename(channel_ptr->mixer_ptr->jack_client, channel_ptr->port_left, name);
231 /* what could we do here? */
238 jack_mixer_channel_t channel)
240 return channel_ptr->stereo;
244 channel_get_balance_midi_cc(
245 jack_mixer_channel_t channel)
247 return channel_ptr->midi_cc_balance_index;
251 channel_unset_midi_cc_map(
252 jack_mixer_channel_t channel,
254 if (channel_ptr->mixer_ptr->midi_cc_map[new_cc]->midi_cc_volume_index == new_cc) {
255 channel_ptr->mixer_ptr->midi_cc_map[new_cc]->midi_cc_volume_index = -1;
256 } else if (channel_ptr->mixer_ptr->midi_cc_map[new_cc]->midi_cc_balance_index == new_cc) {
257 channel_ptr->mixer_ptr->midi_cc_map[new_cc]->midi_cc_balance_index = -1;
258 } else if (channel_ptr->mixer_ptr->midi_cc_map[new_cc]->midi_cc_mute_index == new_cc) {
259 channel_ptr->mixer_ptr->midi_cc_map[new_cc]->midi_cc_mute_index = -1;
260 } else if (channel_ptr->mixer_ptr->midi_cc_map[new_cc]->midi_cc_solo_index == new_cc) {
261 channel_ptr->mixer_ptr->midi_cc_map[new_cc]->midi_cc_solo_index = -1;
266 channel_set_balance_midi_cc(
267 jack_mixer_channel_t channel,
270 if (new_cc < 0 || new_cc > 127) {
271 return 2; /* error: outside limit CC */
273 if (channel_ptr->mixer_ptr->midi_cc_map[new_cc] != NULL) {
274 channel_unset_midi_cc_map(channel, new_cc);
276 if (channel_ptr->midi_cc_balance_index != -1) {
277 channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_balance_index] = NULL;
279 channel_ptr->mixer_ptr->midi_cc_map[new_cc] = channel_ptr;
280 channel_ptr->midi_cc_balance_index = new_cc;
285 channel_get_volume_midi_cc(
286 jack_mixer_channel_t channel)
288 return channel_ptr->midi_cc_volume_index;
292 channel_set_volume_midi_cc(
293 jack_mixer_channel_t channel, int new_cc)
295 if (new_cc< 0 || new_cc > 127) {
296 return 2; /* error: outside limit CC */
298 if (channel_ptr->mixer_ptr->midi_cc_map[new_cc] != NULL) {
299 channel_unset_midi_cc_map(channel, new_cc);
301 if (channel_ptr->midi_cc_volume_index != -1) {
302 channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_volume_index] = NULL;
304 channel_ptr->mixer_ptr->midi_cc_map[new_cc] = channel_ptr;
305 channel_ptr->midi_cc_volume_index = new_cc;
310 channel_get_mute_midi_cc(
311 jack_mixer_channel_t channel)
313 return channel_ptr->midi_cc_mute_index;
317 channel_set_mute_midi_cc(
318 jack_mixer_channel_t channel,
321 if (new_cc < 0 || new_cc > 127) {
322 return 2; /* error: outside limit CC */
324 if (channel_ptr->mixer_ptr->midi_cc_map[new_cc] != NULL) {
325 channel_unset_midi_cc_map(channel, new_cc);
328 if (channel_ptr->midi_cc_mute_index != -1) {
329 channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_mute_index] = NULL;
331 channel_ptr->mixer_ptr->midi_cc_map[new_cc] = channel_ptr;
332 channel_ptr->midi_cc_mute_index = new_cc;
337 channel_get_solo_midi_cc(
338 jack_mixer_channel_t channel)
340 return channel_ptr->midi_cc_solo_index;
343 void channel_set_midi_cc_volume_picked_up(jack_mixer_channel_t channel, bool status)
345 LOG_DEBUG("Setting channel %s volume picked up to %d", channel_ptr->name, status);
346 channel_ptr->midi_cc_volume_picked_up = status;
349 void channel_set_midi_cc_balance_picked_up(jack_mixer_channel_t channel, bool status)
351 LOG_DEBUG("Setting channel %s balance picked up to %d", channel_ptr->name, status);
352 channel_ptr->midi_cc_balance_picked_up = status;
356 channel_set_solo_midi_cc(
357 jack_mixer_channel_t channel,
360 if (new_cc < 0 || new_cc > 127) {
361 return 2; /* error: outside limit CC */
363 if (channel_ptr->mixer_ptr->midi_cc_map[new_cc] != NULL) {
364 channel_unset_midi_cc_map(channel, new_cc);
366 if (channel_ptr->midi_cc_solo_index != -1) {
367 channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_solo_index] = NULL;
369 channel_ptr->mixer_ptr->midi_cc_map[new_cc] = channel_ptr;
370 channel_ptr->midi_cc_solo_index = new_cc;
375 channel_autoset_volume_midi_cc(
376 jack_mixer_channel_t channel)
378 struct jack_mixer *mixer_ptr = channel_ptr->mixer_ptr;
380 for (int i = 11 ; i < 128 ; i++)
382 if (mixer_ptr->midi_cc_map[i] == NULL)
384 mixer_ptr->midi_cc_map[i] = channel_ptr;
385 channel_ptr->midi_cc_volume_index = i;
387 LOG_NOTICE("New channel \"%s\" volume mapped to CC#%i", channel_ptr->name, i);
395 channel_autoset_balance_midi_cc(
396 jack_mixer_channel_t channel)
398 struct jack_mixer *mixer_ptr = channel_ptr->mixer_ptr;
400 for (int i = 11; i < 128 ; i++)
402 if (mixer_ptr->midi_cc_map[i] == NULL)
404 mixer_ptr->midi_cc_map[i] = channel_ptr;
405 channel_ptr->midi_cc_balance_index = i;
407 LOG_NOTICE("New channel \"%s\" balance mapped to CC#%i", channel_ptr->name, i);
415 channel_autoset_mute_midi_cc(
416 jack_mixer_channel_t channel)
418 struct jack_mixer *mixer_ptr = channel_ptr->mixer_ptr;
420 for (int i = 11; i < 128 ; i++)
422 if (mixer_ptr->midi_cc_map[i] == NULL)
424 mixer_ptr->midi_cc_map[i] = channel_ptr;
425 channel_ptr->midi_cc_mute_index = i;
427 LOG_NOTICE("New channel \"%s\" mute mapped to CC#%i", channel_ptr->name, i);
435 channel_autoset_solo_midi_cc(
436 jack_mixer_channel_t channel)
438 struct jack_mixer *mixer_ptr = channel_ptr->mixer_ptr;
440 for (int i = 11; i < 128 ; i++)
442 if (mixer_ptr->midi_cc_map[i] == NULL)
444 mixer_ptr->midi_cc_map[i] = channel_ptr;
445 channel_ptr->midi_cc_solo_index = i;
447 LOG_NOTICE("New channel \"%s\" solo mapped to CC#%i", channel_ptr->name, i);
456 jack_mixer_channel_t channel)
459 channel_ptr->mixer_ptr->input_channels_list = g_slist_remove(
460 channel_ptr->mixer_ptr->input_channels_list, channel_ptr);
461 free(channel_ptr->name);
463 /* remove references to input channel from all output channels */
464 for (list_ptr = channel_ptr->mixer_ptr->output_channels_list; list_ptr; list_ptr = g_slist_next(list_ptr))
466 struct output_channel *output_channel_ptr = list_ptr->data;
467 output_channel_set_solo(output_channel_ptr, channel, false);
468 output_channel_set_muted(output_channel_ptr, channel, false);
471 jack_port_unregister(channel_ptr->mixer_ptr->jack_client, channel_ptr->port_left);
472 if (channel_ptr->stereo)
474 jack_port_unregister(channel_ptr->mixer_ptr->jack_client, channel_ptr->port_right);
477 if (channel_ptr->midi_cc_volume_index != -1)
479 assert(channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_volume_index] == channel_ptr);
480 channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_volume_index] = NULL;
483 if (channel_ptr->midi_cc_balance_index != -1)
485 assert(channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_balance_index] == channel_ptr);
486 channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_balance_index] = NULL;
489 if (channel_ptr->midi_cc_mute_index != -1)
491 assert(channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_mute_index] == channel_ptr);
492 channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_mute_index] = NULL;
494 if (channel_ptr->midi_cc_solo_index != -1)
496 assert(channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_solo_index] == channel_ptr);
497 channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_solo_index] = NULL;
500 free(channel_ptr->frames_left);
501 free(channel_ptr->frames_right);
502 free(channel_ptr->prefader_frames_left);
503 free(channel_ptr->prefader_frames_right);
509 channel_stereo_meter_read(
510 jack_mixer_channel_t channel,
515 *left_ptr = value_to_db(channel_ptr->meter_left);
516 *right_ptr = value_to_db(channel_ptr->meter_right);
520 channel_mono_meter_read(
521 jack_mixer_channel_t channel,
524 *mono_ptr = value_to_db(channel_ptr->meter_left);
528 channel_volume_write(
529 jack_mixer_channel_t channel,
533 /*If changing volume and find we're in the middle of a previous transition,
534 *then set current volume to place in transition to avoid a jump.*/
535 if (channel_ptr->volume_new != channel_ptr->volume) {
536 channel_ptr->volume = channel_ptr->volume + channel_ptr->volume_idx *
537 (channel_ptr->volume_new - channel_ptr->volume) /
538 channel_ptr->num_volume_transition_steps;
540 channel_ptr->volume_idx = 0;
541 channel_ptr->volume_new = db_to_value(volume);
542 channel_ptr->midi_out_has_events = true;
547 jack_mixer_channel_t channel)
550 return value_to_db(channel_ptr->volume_new);
554 channels_volumes_read(jack_mixer_t mixer_ptr)
557 struct channel *pChannel;
558 struct jack_mixer * pMixer = (struct jack_mixer *)mixer_ptr;
560 for (node_ptr = pMixer->input_channels_list; node_ptr; node_ptr = g_slist_next(node_ptr))
562 pChannel = (struct channel *)node_ptr->data;
563 double vol = channel_volume_read( (jack_mixer_channel_t)pChannel);
564 printf("%s : volume is %f dbFS for mixer channel: %s\n", jack_get_client_name(pMixer->jack_client), vol, pChannel->name);
569 channel_balance_write(
570 jack_mixer_channel_t channel,
574 if (channel_ptr->balance != channel_ptr->balance_new) {
575 channel_ptr->balance = channel_ptr->balance + channel_ptr->balance_idx *
576 (channel_ptr->balance_new - channel_ptr->balance) /
577 channel_ptr->num_volume_transition_steps;
579 channel_ptr->balance_idx = 0;
580 channel_ptr->balance_new = balance;
584 channel_balance_read(
585 jack_mixer_channel_t channel)
588 return channel_ptr->balance_new;
592 channel_abspeak_read(
593 jack_mixer_channel_t channel)
596 if (channel_ptr->NaN_detected)
602 return value_to_db(channel_ptr->abspeak);
607 channel_abspeak_reset(
608 jack_mixer_channel_t channel)
610 channel_ptr->abspeak = 0;
611 channel_ptr->NaN_detected = false;
616 jack_mixer_channel_t channel)
618 channel_ptr->out_mute = true;
623 jack_mixer_channel_t channel)
625 channel_ptr->out_mute = false;
629 channel_is_out_muted(
630 jack_mixer_channel_t channel)
632 return channel_ptr->out_mute;
637 jack_mixer_channel_t channel)
639 if (g_slist_find(channel_ptr->mixer_ptr->soloed_channels, channel) != NULL)
641 channel_ptr->mixer_ptr->soloed_channels = g_slist_prepend(channel_ptr->mixer_ptr->soloed_channels, channel);
646 jack_mixer_channel_t channel)
648 if (g_slist_find(channel_ptr->mixer_ptr->soloed_channels, channel) == NULL)
650 channel_ptr->mixer_ptr->soloed_channels = g_slist_remove(channel_ptr->mixer_ptr->soloed_channels, channel);
655 jack_mixer_channel_t channel)
657 if (g_slist_find(channel_ptr->mixer_ptr->soloed_channels, channel))
663 channel_set_midi_scale(
664 jack_mixer_channel_t channel,
665 jack_mixer_scale_t scale)
667 channel_ptr->midi_scale = scale;
671 channel_set_midi_change_callback(
672 jack_mixer_channel_t channel,
673 void (*midi_change_callback) (void*),
676 channel_ptr->midi_change_callback = midi_change_callback;
677 channel_ptr->midi_change_callback_data = user_data;
681 channel_get_midi_in_got_events(
682 jack_mixer_channel_t channel)
684 bool t = channel_ptr->midi_in_got_events;
685 channel_ptr->midi_in_got_events = false;
691 /* process input channels and mix them into main mix */
694 struct output_channel *output_mix_channel,
695 GSList *channels_list,
696 jack_nframes_t start, /* index of first sample to process */
697 jack_nframes_t end) /* index of sample to stop processing before */
701 struct channel * channel_ptr;
702 jack_default_audio_sample_t frame_left;
703 jack_default_audio_sample_t frame_right;
704 struct channel *mix_channel = (struct channel*)output_mix_channel;
706 for (i = start; i < end; i++)
708 mix_channel->left_buffer_ptr[i] = mix_channel->tmp_mixed_frames_left[i] = 0.0;
709 if (mix_channel->stereo)
710 mix_channel->right_buffer_ptr[i] = mix_channel->tmp_mixed_frames_right[i] = 0.0;
713 for (node_ptr = channels_list; node_ptr; node_ptr = g_slist_next(node_ptr))
715 channel_ptr = node_ptr->data;
717 if (g_slist_find(output_mix_channel->muted_channels, channel_ptr) != NULL || channel_ptr->out_mute) {
718 /* skip muted channels */
722 if ((!channel_ptr->mixer_ptr->soloed_channels && !output_mix_channel->soloed_channels) ||
723 (channel_ptr->mixer_ptr->soloed_channels &&
724 g_slist_find(channel_ptr->mixer_ptr->soloed_channels, channel_ptr) != NULL) ||
725 (output_mix_channel->soloed_channels &&
726 g_slist_find(output_mix_channel->soloed_channels, channel_ptr) != NULL)) {
728 for (i = start ; i < end ; i++)
730 if (! output_mix_channel->prefader) {
731 frame_left = channel_ptr->frames_left[i-start];
733 frame_left = channel_ptr->prefader_frames_left[i-start];
735 if (frame_left == NAN)
737 mix_channel->tmp_mixed_frames_left[i] += frame_left;
738 if (mix_channel->stereo)
740 if (! output_mix_channel->prefader) {
741 frame_right = channel_ptr->frames_right[i-start];
743 frame_right = channel_ptr->prefader_frames_right[i-start];
745 if (frame_right == NAN)
747 mix_channel->tmp_mixed_frames_right[i] += frame_right;
753 /* process main mix channel */
754 unsigned int steps = mix_channel->num_volume_transition_steps;
755 for (i = start ; i < end ; i++)
757 if (! output_mix_channel->prefader) {
758 float volume = mix_channel->volume;
759 float volume_new = mix_channel->volume_new;
761 float balance = mix_channel->balance;
762 float balance_new = mix_channel->balance_new;
764 if (volume != volume_new) {
765 vol = mix_channel->volume_idx * (volume_new - volume) / steps + volume;
767 if (balance != balance_new) {
768 bal = mix_channel->balance_idx * (balance_new - balance) / steps + balance;
773 if (mix_channel->stereo) {
775 vol_l = vol * (1 - bal);
779 vol_r = vol * (1 + bal);
782 vol_l = vol * (1 - bal);
783 vol_r = vol * (1 + bal);
785 mix_channel->tmp_mixed_frames_left[i] *= vol_l;
786 mix_channel->tmp_mixed_frames_right[i] *= vol_r;
789 frame_left = fabsf(mix_channel->tmp_mixed_frames_left[i]);
790 if (mix_channel->peak_left < frame_left)
792 mix_channel->peak_left = frame_left;
794 if (frame_left > mix_channel->abspeak)
796 mix_channel->abspeak = frame_left;
800 if (mix_channel->stereo)
802 frame_right = fabsf(mix_channel->tmp_mixed_frames_right[i]);
803 if (mix_channel->peak_right < frame_right)
805 mix_channel->peak_right = frame_right;
807 if (frame_right > mix_channel->abspeak)
809 mix_channel->abspeak = frame_right;
814 mix_channel->peak_frames++;
815 if (mix_channel->peak_frames >= PEAK_FRAMES_CHUNK)
817 mix_channel->meter_left = mix_channel->peak_left;
818 mix_channel->peak_left = 0.0;
820 if (mix_channel->stereo)
822 mix_channel->meter_right = mix_channel->peak_right;
823 mix_channel->peak_right = 0.0;
826 mix_channel->peak_frames = 0;
828 mix_channel->volume_idx++;
829 if ((mix_channel->volume != mix_channel->volume_new) && (mix_channel->volume_idx == steps)) {
830 mix_channel->volume = mix_channel->volume_new;
831 mix_channel->volume_idx = 0;
833 mix_channel->balance_idx++;
834 if ((mix_channel->balance != mix_channel->balance_new) && (mix_channel->balance_idx == steps)) {
835 mix_channel->balance = mix_channel->balance_new;
836 mix_channel->balance_idx = 0;
839 if (!mix_channel->out_mute) {
840 mix_channel->left_buffer_ptr[i] = mix_channel->tmp_mixed_frames_left[i];
841 if (mix_channel->stereo)
842 mix_channel->right_buffer_ptr[i] = mix_channel->tmp_mixed_frames_right[i];
849 struct channel *channel_ptr,
850 jack_nframes_t start,
854 jack_default_audio_sample_t frame_left = 0.0f;
855 jack_default_audio_sample_t frame_right = 0.0f;
856 unsigned int steps = channel_ptr->num_volume_transition_steps;
857 for (i = start ; i < end ; i++)
859 if (i-start >= MAX_BLOCK_SIZE)
861 fprintf(stderr, "i-start too high: %d - %d\n", i, start);
863 channel_ptr->prefader_frames_left[i-start] = channel_ptr->left_buffer_ptr[i];
864 if (channel_ptr->stereo)
865 channel_ptr->prefader_frames_right[i-start] = channel_ptr->right_buffer_ptr[i];
867 if (!FLOAT_EXISTS(channel_ptr->left_buffer_ptr[i]))
869 channel_ptr->NaN_detected = true;
870 channel_ptr->frames_left[i-start] = NAN;
873 float volume = channel_ptr->volume;
874 float volume_new = channel_ptr->volume_new;
876 float balance = channel_ptr->balance;
877 float balance_new = channel_ptr->balance_new;
879 if (channel_ptr->volume != channel_ptr->volume_new) {
880 vol = channel_ptr->volume_idx * (volume_new - volume) / steps + volume;
882 if (channel_ptr->balance != channel_ptr->balance_new) {
883 bal = channel_ptr->balance_idx * (balance_new - balance) / steps + balance;
887 if (channel_ptr->stereo) {
889 vol_l = vol * (1 - bal);
893 vol_r = vol * (1 + bal);
896 vol_l = vol * (1 - bal);
897 vol_r = vol * (1 + bal);
899 frame_left = channel_ptr->left_buffer_ptr[i] * vol_l;
900 if (channel_ptr->stereo)
902 if (!FLOAT_EXISTS(channel_ptr->right_buffer_ptr[i]))
904 channel_ptr->NaN_detected = true;
905 channel_ptr->frames_right[i-start] = NAN;
909 frame_right = channel_ptr->right_buffer_ptr[i] * vol_r;
912 channel_ptr->frames_left[i-start] = frame_left;
913 channel_ptr->frames_right[i-start] = frame_right;
915 if (channel_ptr->stereo)
917 frame_left = fabsf(frame_left);
918 frame_right = fabsf(frame_right);
920 if (channel_ptr->peak_left < frame_left)
922 channel_ptr->peak_left = frame_left;
924 if (frame_left > channel_ptr->abspeak)
926 channel_ptr->abspeak = frame_left;
930 if (channel_ptr->peak_right < frame_right)
932 channel_ptr->peak_right = frame_right;
934 if (frame_right > channel_ptr->abspeak)
936 channel_ptr->abspeak = frame_right;
942 frame_left = (fabsf(frame_left) + fabsf(frame_right)) / 2;
944 if (channel_ptr->peak_left < frame_left)
946 channel_ptr->peak_left = frame_left;
948 if (frame_left > channel_ptr->abspeak)
950 channel_ptr->abspeak = frame_left;
955 channel_ptr->peak_frames++;
956 if (channel_ptr->peak_frames >= PEAK_FRAMES_CHUNK)
958 channel_ptr->meter_left = channel_ptr->peak_left;
959 channel_ptr->peak_left = 0.0;
961 if (channel_ptr->stereo)
963 channel_ptr->meter_right = channel_ptr->peak_right;
964 channel_ptr->peak_right = 0.0;
967 channel_ptr->peak_frames = 0;
969 channel_ptr->volume_idx++;
970 if ((channel_ptr->volume != channel_ptr->volume_new) &&
971 (channel_ptr->volume_idx == steps)) {
972 channel_ptr->volume = channel_ptr->volume_new;
973 channel_ptr->volume_idx = 0;
975 channel_ptr->balance_idx++;
976 if ((channel_ptr->balance != channel_ptr->balance_new) &&
977 (channel_ptr->balance_idx >= steps)) {
978 channel_ptr->balance = channel_ptr->balance_new;
979 channel_ptr->balance_idx = 0;
986 struct jack_mixer * mixer_ptr,
987 jack_nframes_t start, /* index of first sample to process */
988 jack_nframes_t end) /* index of sample to stop processing before */
991 struct output_channel * output_channel_ptr;
992 struct channel *channel_ptr;
994 for (node_ptr = mixer_ptr->input_channels_list; node_ptr; node_ptr = g_slist_next(node_ptr))
996 channel_ptr = (struct channel*)node_ptr->data;
997 calc_channel_frames(channel_ptr, start, end);
1000 for (node_ptr = mixer_ptr->output_channels_list; node_ptr; node_ptr = g_slist_next(node_ptr))
1002 output_channel_ptr = node_ptr->data;
1003 channel_ptr = (struct channel*)output_channel_ptr;
1005 if (output_channel_ptr->system)
1007 /* Don't bother mixing the channels if we are not connected */
1008 if (channel_ptr->stereo)
1010 if (jack_port_connected(channel_ptr->port_left) == 0 &&
1011 jack_port_connected(channel_ptr->port_right) == 0)
1014 if (jack_port_connected(channel_ptr->port_left) == 0)
1019 mix_one(output_channel_ptr, mixer_ptr->input_channels_list, start, end);
1024 update_channel_buffers(
1025 struct channel * channel_ptr,
1026 jack_nframes_t nframes)
1028 channel_ptr->left_buffer_ptr = jack_port_get_buffer(channel_ptr->port_left, nframes);
1030 if (channel_ptr->stereo)
1032 channel_ptr->right_buffer_ptr = jack_port_get_buffer(channel_ptr->port_right, nframes);
1036 #define mixer_ptr ((struct jack_mixer *)context)
1040 jack_nframes_t nframes,
1045 struct channel * channel_ptr;
1046 #if defined(HAVE_JACK_MIDI)
1047 jack_nframes_t event_count;
1048 jack_midi_event_t in_event;
1049 unsigned char* midi_out_buffer;
1052 unsigned int cc_channel_index;
1055 for (node_ptr = mixer_ptr->input_channels_list; node_ptr; node_ptr = g_slist_next(node_ptr))
1057 channel_ptr = node_ptr->data;
1058 update_channel_buffers(channel_ptr, nframes);
1061 // Fill output buffers with the input
1062 for (node_ptr = mixer_ptr->output_channels_list; node_ptr; node_ptr = g_slist_next(node_ptr))
1064 channel_ptr = node_ptr->data;
1065 update_channel_buffers(channel_ptr, nframes);
1068 #if defined(HAVE_JACK_MIDI)
1069 midi_buffer = jack_port_get_buffer(mixer_ptr->port_midi_in, nframes);
1070 event_count = jack_midi_get_event_count(midi_buffer);
1072 for (i = 0 ; i < event_count; i++)
1074 jack_midi_event_get(&in_event, midi_buffer, i);
1076 if (in_event.size != 3 ||
1077 (in_event.buffer[0] & 0xF0) != 0xB0 ||
1078 in_event.buffer[1] > 127 ||
1079 in_event.buffer[2] > 127)
1084 assert(in_event.time < nframes);
1088 (unsigned int)(in_event.buffer[0]),
1089 (unsigned int)in_event.buffer[1],
1090 (unsigned int)in_event.buffer[2]);
1092 mixer_ptr->last_midi_channel = (int)in_event.buffer[1];
1093 channel_ptr = mixer_ptr->midi_cc_map[in_event.buffer[1]];
1095 /* if we have mapping for particular CC and MIDI scale is set for corresponding channel */
1096 if (channel_ptr != NULL && channel_ptr->midi_scale != NULL)
1098 if (channel_ptr->midi_cc_balance_index == (char)in_event.buffer[1])
1100 byte = in_event.buffer[2];
1106 int current_midi = (int)63 * channel_ptr->balance + 64;
1107 current_midi = current_midi == 1 ? 0 : current_midi;
1108 if (mixer_ptr->midi_behavior == Pick_Up &&
1109 !channel_ptr->midi_cc_balance_picked_up) {
1110 if (in_event.buffer[2] == current_midi) {
1111 channel_set_midi_cc_balance_picked_up(channel_ptr, true);
1114 if ((mixer_ptr->midi_behavior == Pick_Up &&
1115 channel_ptr->midi_cc_balance_picked_up) ||
1116 mixer_ptr->midi_behavior == Jump_To_Value) {
1117 if (channel_ptr->balance != channel_ptr->balance_new) {
1118 channel_ptr->balance = channel_ptr->balance + channel_ptr->balance_idx *
1119 (channel_ptr->balance_new - channel_ptr->balance) /
1120 channel_ptr->num_volume_transition_steps;
1122 channel_ptr->balance_idx = 0;
1123 channel_ptr->balance_new = (float)byte / 63;
1124 LOG_DEBUG("\"%s\" balance -> %f", channel_ptr->name, channel_ptr->balance_new);
1127 else if (channel_ptr->midi_cc_volume_index == in_event.buffer[1])
1129 int current_midi = (int)(127 *
1130 scale_db_to_scale(channel_ptr->midi_scale,
1131 value_to_db(channel_ptr->volume)));
1132 if (mixer_ptr->midi_behavior == Pick_Up &&
1133 !channel_ptr->midi_cc_volume_picked_up ) {
1134 if (in_event.buffer[2] == current_midi) {
1135 channel_set_midi_cc_volume_picked_up(channel_ptr, true);
1138 if ((mixer_ptr->midi_behavior == Pick_Up &&
1139 channel_ptr->midi_cc_volume_picked_up) ||
1140 mixer_ptr->midi_behavior == Jump_To_Value) {
1141 if (channel_ptr->volume_new != channel_ptr->volume) {
1142 channel_ptr->volume = channel_ptr->volume + channel_ptr->volume_idx *
1143 (channel_ptr->volume_new - channel_ptr->volume) /
1144 channel_ptr->num_volume_transition_steps;
1146 channel_ptr->volume_idx = 0;
1147 channel_ptr->volume_new = db_to_value(scale_scale_to_db(channel_ptr->midi_scale,
1148 (double)in_event.buffer[2] / 127));
1149 LOG_DEBUG("\"%s\" volume -> %f", channel_ptr->name, channel_ptr->volume_new);
1152 else if (channel_ptr->midi_cc_mute_index == in_event.buffer[1])
1154 if ((unsigned int)in_event.buffer[2] == 127) {
1155 channel_ptr->out_mute = !channel_ptr->out_mute;
1157 LOG_DEBUG("\"%s\" out_mute %d", channel_ptr->name, channel_ptr->out_mute);
1159 else if (channel_ptr->midi_cc_solo_index == in_event.buffer[1])
1161 if ((unsigned int)in_event.buffer[2] == 127) {
1162 if (channel_is_soloed(channel_ptr)) {
1163 channel_unsolo(channel_ptr);
1165 channel_solo(channel_ptr);
1168 LOG_DEBUG("\"%s\" solo %d", channel_ptr->name, channel_is_soloed(channel_ptr));
1170 channel_ptr->midi_in_got_events = true;
1171 if (channel_ptr->midi_change_callback)
1172 channel_ptr->midi_change_callback(channel_ptr->midi_change_callback_data);
1178 midi_buffer = jack_port_get_buffer(mixer_ptr->port_midi_out, nframes);
1179 jack_midi_clear_buffer(midi_buffer);
1181 for(i=0; i<nframes; i++)
1183 for (cc_channel_index=0; cc_channel_index<128; cc_channel_index++)
1185 channel_ptr = mixer_ptr->midi_cc_map[cc_channel_index];
1186 if (channel_ptr == NULL || channel_ptr->midi_scale == NULL)
1190 if (channel_ptr->midi_out_has_events == false)
1194 if (channel_ptr->midi_cc_balance_index == (int)cc_channel_index)
1198 midi_out_buffer = jack_midi_event_reserve(midi_buffer, i, 3);
1199 if (midi_out_buffer == NULL)
1203 midi_out_buffer[0] = 0xB0; /* control change */
1204 midi_out_buffer[1] = cc_channel_index;
1205 midi_out_buffer[2] = (unsigned char)(127*scale_db_to_scale(channel_ptr->midi_scale, value_to_db(channel_ptr->volume_new)));
1209 (unsigned int)(midi_out_buffer[0]),
1210 (unsigned int)midi_out_buffer[1],
1211 (unsigned int)midi_out_buffer[2]);
1213 channel_ptr->midi_out_has_events = false;
1219 mix(mixer_ptr, 0, nframes);
1228 const char * jack_client_name_ptr,
1233 struct jack_mixer * mixer_ptr;
1237 mixer_ptr = malloc(sizeof(struct jack_mixer));
1238 if (mixer_ptr == NULL)
1243 ret = pthread_mutex_init(&mixer_ptr->mutex, NULL);
1249 mixer_ptr->input_channels_list = NULL;
1250 mixer_ptr->output_channels_list = NULL;
1252 mixer_ptr->soloed_channels = NULL;
1254 mixer_ptr->last_midi_channel = -1;
1256 mixer_ptr->midi_behavior = Jump_To_Value;
1258 for (i = 0 ; i < 128 ; i++)
1260 mixer_ptr->midi_cc_map[i] = NULL;
1263 LOG_DEBUG("Initializing JACK");
1264 mixer_ptr->jack_client = jack_client_open(jack_client_name_ptr, 0, NULL);
1265 if (mixer_ptr->jack_client == NULL)
1267 LOG_ERROR("Cannot create JACK client.");
1268 LOG_NOTICE("Please make sure JACK daemon is running.");
1269 goto exit_destroy_mutex;
1272 LOG_DEBUG("JACK client created");
1274 LOG_DEBUG("Sample rate: %" PRIu32, jack_get_sample_rate(mixer_ptr->jack_client));
1277 #if defined(HAVE_JACK_MIDI)
1278 mixer_ptr->port_midi_in = jack_port_register(mixer_ptr->jack_client, "midi in", JACK_DEFAULT_MIDI_TYPE, JackPortIsInput, 0);
1279 if (mixer_ptr->port_midi_in == NULL)
1281 LOG_ERROR("Cannot create JACK MIDI in port");
1285 mixer_ptr->port_midi_out = jack_port_register(mixer_ptr->jack_client, "midi out", JACK_DEFAULT_MIDI_TYPE, JackPortIsOutput, 0);
1286 if (mixer_ptr->port_midi_out == NULL)
1288 LOG_ERROR("Cannot create JACK MIDI out port");
1294 ret = jack_set_process_callback(mixer_ptr->jack_client, process, mixer_ptr);
1297 LOG_ERROR("Cannot set JACK process callback");
1301 ret = jack_activate(mixer_ptr->jack_client);
1304 LOG_ERROR("Cannot activate JACK client");
1311 jack_client_close(mixer_ptr->jack_client); /* this should clear all other resources we obtained through the client handle */
1314 pthread_mutex_destroy(&mixer_ptr->mutex);
1323 #define mixer_ctx_ptr ((struct jack_mixer *)mixer)
1329 LOG_DEBUG("Uninitializing JACK");
1331 assert(mixer_ctx_ptr->jack_client != NULL);
1333 jack_client_close(mixer_ctx_ptr->jack_client);
1335 pthread_mutex_destroy(&mixer_ctx_ptr->mutex);
1337 free(mixer_ctx_ptr);
1345 return g_slist_length(mixer_ctx_ptr->input_channels_list);
1352 return jack_get_client_name(mixer_ctx_ptr->jack_client);
1356 get_last_midi_channel(
1359 return mixer_ctx_ptr->last_midi_channel;
1363 set_last_midi_channel(
1366 mixer_ctx_ptr->last_midi_channel = new_channel;
1371 get_midi_behavior_mode(
1374 return mixer_ctx_ptr->midi_behavior;
1378 set_midi_behavior_mode(
1380 enum midi_behavior_mode mode)
1382 mixer_ctx_ptr->midi_behavior = mode;
1386 jack_mixer_channel_t
1389 const char * channel_name,
1392 struct channel * channel_ptr;
1393 char * port_name = NULL;
1394 size_t channel_name_size;
1396 channel_ptr = malloc(sizeof(struct channel));
1397 if (channel_ptr == NULL)
1402 channel_ptr->mixer_ptr = mixer_ctx_ptr;
1404 channel_ptr->name = strdup(channel_name);
1405 if (channel_ptr->name == NULL)
1407 goto fail_free_channel;
1410 channel_name_size = strlen(channel_name);
1414 port_name = malloc(channel_name_size + 3);
1415 if (port_name == NULL)
1417 goto fail_free_channel_name;
1420 memcpy(port_name, channel_name, channel_name_size);
1421 port_name[channel_name_size] = ' ';
1422 port_name[channel_name_size+1] = 'L';
1423 port_name[channel_name_size+2] = 0;
1425 channel_ptr->port_left = jack_port_register(channel_ptr->mixer_ptr->jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
1426 if (channel_ptr->port_left == NULL)
1428 goto fail_free_port_name;
1431 port_name[channel_name_size+1] = 'R';
1433 channel_ptr->port_right = jack_port_register(channel_ptr->mixer_ptr->jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
1434 if (channel_ptr->port_right == NULL)
1436 goto fail_unregister_left_channel;
1441 channel_ptr->port_left = jack_port_register(channel_ptr->mixer_ptr->jack_client, channel_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsInput, 0);
1442 if (channel_ptr->port_left == NULL)
1444 goto fail_free_channel_name;
1448 channel_ptr->stereo = stereo;
1450 channel_ptr->volume_transition_seconds = VOLUME_TRANSITION_SECONDS;
1451 channel_ptr->num_volume_transition_steps =
1452 channel_ptr->volume_transition_seconds *
1453 jack_get_sample_rate(channel_ptr->mixer_ptr->jack_client) + 1;
1454 channel_ptr->volume = 0.0;
1455 channel_ptr->volume_new = 0.0;
1456 channel_ptr->balance = 0.0;
1457 channel_ptr->balance_new = 0.0;
1458 channel_ptr->meter_left = -1.0;
1459 channel_ptr->meter_right = -1.0;
1460 channel_ptr->abspeak = 0.0;
1461 channel_ptr->out_mute = false;
1463 channel_ptr->peak_left = 0.0;
1464 channel_ptr->peak_right = 0.0;
1465 channel_ptr->peak_frames = 0;
1467 channel_ptr->frames_left = calloc(MAX_BLOCK_SIZE, sizeof(jack_default_audio_sample_t));
1468 channel_ptr->frames_right = calloc(MAX_BLOCK_SIZE, sizeof(jack_default_audio_sample_t));
1469 channel_ptr->prefader_frames_left = calloc(MAX_BLOCK_SIZE, sizeof(jack_default_audio_sample_t));
1470 channel_ptr->prefader_frames_right = calloc(MAX_BLOCK_SIZE, sizeof(jack_default_audio_sample_t));
1472 channel_ptr->NaN_detected = false;
1474 channel_ptr->midi_cc_volume_index = -1;
1475 channel_ptr->midi_cc_balance_index = -1;
1476 channel_ptr->midi_cc_mute_index = -1;
1477 channel_ptr->midi_cc_solo_index = -1;
1478 channel_ptr->midi_cc_volume_picked_up = false;
1479 channel_ptr->midi_cc_balance_picked_up = false;
1481 channel_ptr->midi_change_callback = NULL;
1482 channel_ptr->midi_change_callback_data = NULL;
1483 channel_ptr->midi_out_has_events = false;
1485 channel_ptr->midi_scale = NULL;
1487 channel_ptr->mixer_ptr->input_channels_list = g_slist_prepend(
1488 channel_ptr->mixer_ptr->input_channels_list, channel_ptr);
1493 fail_unregister_left_channel:
1494 jack_port_unregister(channel_ptr->mixer_ptr->jack_client, channel_ptr->port_left);
1496 fail_free_port_name:
1499 fail_free_channel_name:
1500 free(channel_ptr->name);
1510 static jack_mixer_output_channel_t
1511 create_output_channel(
1513 const char * channel_name,
1517 struct channel * channel_ptr;
1518 struct output_channel * output_channel_ptr;
1519 char * port_name = NULL;
1520 size_t channel_name_size;
1522 output_channel_ptr = malloc(sizeof(struct output_channel));
1523 channel_ptr = (struct channel*)output_channel_ptr;
1524 if (channel_ptr == NULL)
1529 channel_ptr->mixer_ptr = mixer_ctx_ptr;
1531 channel_ptr->name = strdup(channel_name);
1532 if (channel_ptr->name == NULL)
1534 goto fail_free_channel;
1539 channel_name_size = strlen(channel_name);
1541 port_name = malloc(channel_name_size + 4);
1542 if (port_name == NULL)
1544 goto fail_free_channel_name;
1547 memcpy(port_name, channel_name, channel_name_size);
1548 port_name[channel_name_size] = ' ';
1549 port_name[channel_name_size+1] = 'L';
1550 port_name[channel_name_size+2] = 0;
1552 channel_ptr->port_left = jack_port_register(channel_ptr->mixer_ptr->jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
1553 if (channel_ptr->port_left == NULL)
1555 goto fail_free_port_name;
1558 port_name[channel_name_size+1] = 'R';
1560 channel_ptr->port_right = jack_port_register(channel_ptr->mixer_ptr->jack_client, port_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
1561 if (channel_ptr->port_right == NULL)
1563 goto fail_unregister_left_channel;
1568 channel_ptr->port_left = jack_port_register(channel_ptr->mixer_ptr->jack_client, channel_name, JACK_DEFAULT_AUDIO_TYPE, JackPortIsOutput, 0);
1569 if (channel_ptr->port_left == NULL)
1571 goto fail_free_channel_name;
1575 channel_ptr->stereo = stereo;
1576 channel_ptr->out_mute = false;
1578 channel_ptr->volume_transition_seconds = VOLUME_TRANSITION_SECONDS;
1579 channel_ptr->num_volume_transition_steps =
1580 channel_ptr->volume_transition_seconds *
1581 jack_get_sample_rate(channel_ptr->mixer_ptr->jack_client) + 1;
1582 channel_ptr->volume = 0.0;
1583 channel_ptr->volume_new = 0.0;
1584 channel_ptr->balance = 0.0;
1585 channel_ptr->balance_new = 0.0;
1586 channel_ptr->meter_left = -1.0;
1587 channel_ptr->meter_right = -1.0;
1588 channel_ptr->abspeak = 0.0;
1590 channel_ptr->peak_left = 0.0;
1591 channel_ptr->peak_right = 0.0;
1592 channel_ptr->peak_frames = 0;
1594 channel_ptr->tmp_mixed_frames_left = calloc(MAX_BLOCK_SIZE, sizeof(jack_default_audio_sample_t));
1595 channel_ptr->tmp_mixed_frames_right = calloc(MAX_BLOCK_SIZE, sizeof(jack_default_audio_sample_t));
1596 channel_ptr->frames_left = calloc(MAX_BLOCK_SIZE, sizeof(jack_default_audio_sample_t));
1597 channel_ptr->frames_right = calloc(MAX_BLOCK_SIZE, sizeof(jack_default_audio_sample_t));
1598 channel_ptr->prefader_frames_left = calloc(MAX_BLOCK_SIZE, sizeof(jack_default_audio_sample_t));
1599 channel_ptr->prefader_frames_right = calloc(MAX_BLOCK_SIZE, sizeof(jack_default_audio_sample_t));
1601 channel_ptr->NaN_detected = false;
1603 channel_ptr->midi_cc_volume_index = -1;
1604 channel_ptr->midi_cc_balance_index = -1;
1605 channel_ptr->midi_cc_mute_index = -1;
1606 channel_ptr->midi_cc_solo_index = -1;
1607 channel_ptr->midi_cc_volume_picked_up = false;
1608 channel_ptr->midi_cc_balance_picked_up = false;
1610 channel_ptr->midi_change_callback = NULL;
1611 channel_ptr->midi_change_callback_data = NULL;
1613 channel_ptr->midi_scale = NULL;
1615 output_channel_ptr->soloed_channels = NULL;
1616 output_channel_ptr->muted_channels = NULL;
1617 output_channel_ptr->system = system;
1618 output_channel_ptr->prefader = false;
1621 return output_channel_ptr;
1623 fail_unregister_left_channel:
1624 jack_port_unregister(channel_ptr->mixer_ptr->jack_client, channel_ptr->port_left);
1626 fail_free_port_name:
1629 fail_free_channel_name:
1630 free(channel_ptr->name);
1640 jack_mixer_output_channel_t
1643 const char * channel_name,
1647 struct output_channel *output_channel_ptr;
1648 struct channel *channel_ptr;
1650 output_channel_ptr = create_output_channel(mixer, channel_name, stereo, system);
1651 if (output_channel_ptr == NULL) {
1654 channel_ptr = (struct channel*)output_channel_ptr;
1656 ((struct jack_mixer*)mixer)->output_channels_list = g_slist_prepend(
1657 ((struct jack_mixer*)mixer)->output_channels_list, channel_ptr);
1659 return output_channel_ptr;
1667 for (list_ptr = mixer_ctx_ptr->input_channels_list; list_ptr; list_ptr = g_slist_next(list_ptr))
1669 struct channel *input_channel_ptr = list_ptr->data;
1670 remove_channel((jack_mixer_channel_t)input_channel_ptr);
1675 remove_output_channel(
1676 jack_mixer_output_channel_t output_channel)
1678 struct output_channel *output_channel_ptr = output_channel;
1679 struct channel *channel_ptr = output_channel;
1681 channel_ptr->mixer_ptr->output_channels_list = g_slist_remove(
1682 channel_ptr->mixer_ptr->output_channels_list, channel_ptr);
1683 free(channel_ptr->name);
1685 jack_port_unregister(channel_ptr->mixer_ptr->jack_client, channel_ptr->port_left);
1686 if (channel_ptr->stereo)
1688 jack_port_unregister(channel_ptr->mixer_ptr->jack_client, channel_ptr->port_right);
1691 if (channel_ptr->midi_cc_volume_index != -1)
1693 assert(channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_volume_index] == channel_ptr);
1694 channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_volume_index] = NULL;
1697 if (channel_ptr->midi_cc_balance_index != -1)
1699 assert(channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_balance_index] == channel_ptr);
1700 channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_balance_index] = NULL;
1703 if (channel_ptr->midi_cc_mute_index != -1)
1705 assert(channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_mute_index] == channel_ptr);
1706 channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_mute_index] = NULL;
1709 if (channel_ptr->midi_cc_solo_index != -1)
1711 assert(channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_solo_index] == channel_ptr);
1712 channel_ptr->mixer_ptr->midi_cc_map[channel_ptr->midi_cc_solo_index] = NULL;
1715 g_slist_free(output_channel_ptr->soloed_channels);
1716 g_slist_free(output_channel_ptr->muted_channels);
1718 free(channel_ptr->tmp_mixed_frames_left);
1719 free(channel_ptr->tmp_mixed_frames_right);
1720 free(channel_ptr->frames_left);
1721 free(channel_ptr->frames_right);
1722 free(channel_ptr->prefader_frames_left);
1723 free(channel_ptr->prefader_frames_right);
1729 output_channel_set_solo(
1730 jack_mixer_output_channel_t output_channel,
1731 jack_mixer_channel_t channel,
1734 struct output_channel *output_channel_ptr = output_channel;
1737 if (g_slist_find(output_channel_ptr->soloed_channels, channel) != NULL)
1739 output_channel_ptr->soloed_channels = g_slist_prepend(output_channel_ptr->soloed_channels, channel);
1741 if (g_slist_find(output_channel_ptr->soloed_channels, channel) == NULL)
1743 output_channel_ptr->soloed_channels = g_slist_remove(output_channel_ptr->soloed_channels, channel);
1748 output_channel_set_muted(
1749 jack_mixer_output_channel_t output_channel,
1750 jack_mixer_channel_t channel,
1753 struct output_channel *output_channel_ptr = output_channel;
1756 if (g_slist_find(output_channel_ptr->muted_channels, channel) != NULL)
1758 output_channel_ptr->muted_channels = g_slist_prepend(output_channel_ptr->muted_channels, channel);
1760 if (g_slist_find(output_channel_ptr->muted_channels, channel) == NULL)
1762 output_channel_ptr->muted_channels = g_slist_remove(output_channel_ptr->muted_channels, channel);
1767 output_channel_is_muted(
1768 jack_mixer_output_channel_t output_channel,
1769 jack_mixer_channel_t channel)
1771 struct output_channel *output_channel_ptr = output_channel;
1773 if (g_slist_find(output_channel_ptr->muted_channels, channel) != NULL)
1779 output_channel_is_solo(
1780 jack_mixer_output_channel_t output_channel,
1781 jack_mixer_channel_t channel)
1783 struct output_channel *output_channel_ptr = output_channel;
1785 if (g_slist_find(output_channel_ptr->soloed_channels, channel) != NULL)
1791 output_channel_set_prefader(
1792 jack_mixer_output_channel_t output_channel,
1795 struct output_channel *output_channel_ptr = output_channel;
1796 output_channel_ptr->prefader = pfl_value;
1800 output_channel_is_prefader(
1801 jack_mixer_output_channel_t output_channel)
1803 struct output_channel *output_channel_ptr = output_channel;
1804 return output_channel_ptr->prefader;