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>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
21 *****************************************************************************/
29 #include <jack/jack.h>
30 #if defined(HAVE_JACK_MIDI)
31 #include <jack/midiport.h>
36 #include "jack_mixer.h"
38 //#define LOG_LEVEL LOG_LEVEL_DEBUG
41 #include "jack_compat.h"
43 #define PEAK_FRAMES_CHUNK 4800
45 #define FLOAT_EXISTS(x) (!((x) - (x)))
49 struct list_head siblings
;
50 struct jack_mixer
* mixer_ptr
;
62 jack_port_t
* port_left
;
63 jack_port_t
* port_right
;
65 jack_nframes_t peak_frames
;
71 struct channel
** cc_map_volume_ptr_ptr
;
72 struct channel
** cc_map_balance_ptr_ptr
;
74 jack_default_audio_sample_t
* left_buffer_ptr
;
75 jack_default_audio_sample_t
* right_buffer_ptr
;
79 jack_mixer_scale_t midi_scale
;
84 pthread_mutex_t mutex
;
85 jack_client_t
* jack_client
;
86 struct list_head channels_list
;
87 struct channel main_mix_channel
;
88 unsigned int channels_count
;
89 unsigned int soloed_channels_count
;
91 jack_port_t
* port_midi_in
;
95 bool balance
; /* volume or balance is controlled by this mapping */
96 struct channel
* channel_ptr
;
100 float value_to_db(float value
)
107 return 20.0 * log10f(value
);
110 float db_to_value(float db
)
112 return powf(10.0, db
/20.0);
116 calc_channel_volumes(struct channel
* channel_ptr
)
118 if (channel_ptr
->muted
)
120 channel_ptr
->volume_left
= 0;
121 channel_ptr
->volume_right
= 0;
125 if (channel_ptr
->mixer_ptr
->soloed_channels_count
> 0 && !channel_ptr
->soloed
) /* there are soloed channels but we are not one of them */
127 channel_ptr
->volume_left
= 0;
128 channel_ptr
->volume_right
= 0;
132 if (channel_ptr
->stereo
)
134 if (channel_ptr
->balance
> 0)
136 channel_ptr
->volume_left
= channel_ptr
->volume
* (1 - channel_ptr
->balance
);
137 channel_ptr
->volume_right
= channel_ptr
->volume
;
141 channel_ptr
->volume_left
= channel_ptr
->volume
;
142 channel_ptr
->volume_right
= channel_ptr
->volume
* (1 + channel_ptr
->balance
);
147 channel_ptr
->volume_left
= channel_ptr
->volume
* (1 - channel_ptr
->balance
);
148 channel_ptr
->volume_right
= channel_ptr
->volume
* (1 + channel_ptr
->balance
);
153 calc_all_channel_volumes(
154 struct jack_mixer
* mixer_ptr
)
156 struct list_head
* node_ptr
;
157 struct channel
* channel_ptr
;
159 list_for_each(node_ptr
, &mixer_ptr
->channels_list
)
161 channel_ptr
= list_entry(node_ptr
, struct channel
, siblings
);
162 calc_channel_volumes(channel_ptr
);
166 #define channel_ptr ((struct channel *)channel)
168 const char * channel_get_name(jack_mixer_channel_t channel
)
170 return channel_ptr
->name
;
173 void channel_rename(jack_mixer_channel_t channel
, const char * name
)
176 size_t channel_name_size
;
180 new_name
= strdup(name
);
181 if (new_name
== NULL
)
186 if (channel_ptr
->name
)
188 free(channel_ptr
->name
);
191 channel_ptr
->name
= new_name
;
193 if (channel_ptr
->stereo
)
195 channel_name_size
= strlen(name
);
196 port_name
= malloc(channel_name_size
+ 3);
197 memcpy(port_name
, name
, channel_name_size
);
199 port_name
[channel_name_size
] = ' ';
200 port_name
[channel_name_size
+1] = 'L';
201 port_name
[channel_name_size
+2] = 0;
203 ret
= jack_port_set_name(channel_ptr
->port_left
, port_name
);
206 /* what could we do here? */
209 port_name
[channel_name_size
+1] = 'R';
211 ret
= jack_port_set_name(channel_ptr
->port_right
, port_name
);
214 /* what could we do here? */
221 ret
= jack_port_set_name(channel_ptr
->port_left
, name
);
224 /* what could we do here? */
229 bool channel_is_stereo(jack_mixer_channel_t channel
)
231 return channel_ptr
->stereo
;
234 void remove_channel(jack_mixer_channel_t channel
)
236 list_del(&channel_ptr
->siblings
);
237 free(channel_ptr
->name
);
239 jack_port_unregister(channel_ptr
->mixer_ptr
->jack_client
, channel_ptr
->port_left
);
240 if (channel_ptr
->stereo
)
242 jack_port_unregister(channel_ptr
->mixer_ptr
->jack_client
, channel_ptr
->port_right
);
245 channel_ptr
->mixer_ptr
->channels_count
--;
247 if (channel_ptr
->cc_map_volume_ptr_ptr
!= NULL
)
249 assert(*(channel_ptr
->cc_map_volume_ptr_ptr
) == channel_ptr
);
250 *(channel_ptr
->cc_map_volume_ptr_ptr
) = NULL
;
253 if (channel_ptr
->cc_map_balance_ptr_ptr
!= NULL
)
255 assert(*(channel_ptr
->cc_map_balance_ptr_ptr
) == channel_ptr
);
256 *(channel_ptr
->cc_map_balance_ptr_ptr
) = NULL
;
262 void channel_stereo_meter_read(jack_mixer_channel_t channel
, double * left_ptr
, double * right_ptr
)
265 *left_ptr
= value_to_db(channel_ptr
->meter_left
);
266 *right_ptr
= value_to_db(channel_ptr
->meter_right
);
269 void channel_mono_meter_read(jack_mixer_channel_t channel
, double * mono_ptr
)
271 *mono_ptr
= value_to_db(channel_ptr
->meter_left
);
275 channel_is_midi_modified(
276 jack_mixer_channel_t channel
)
281 midi_modified
= channel_ptr
->midi_modified
;
282 channel_ptr
->midi_modified
= false;
284 return midi_modified
;
287 void channel_volume_write(jack_mixer_channel_t channel
, double volume
)
290 channel_ptr
->volume
= db_to_value(volume
);
291 calc_channel_volumes(channel_ptr
);
296 jack_mixer_channel_t channel
)
299 return value_to_db(channel_ptr
->volume
);
302 void channel_balance_write(jack_mixer_channel_t channel
, double balance
)
305 channel_ptr
->balance
= balance
;
306 calc_channel_volumes(channel_ptr
);
310 channel_balance_read(
311 jack_mixer_channel_t channel
)
314 return channel_ptr
->balance
;
317 double channel_abspeak_read(jack_mixer_channel_t channel
)
320 if (channel_ptr
->NaN_detected
)
326 return value_to_db(channel_ptr
->abspeak
);
330 void channel_abspeak_reset(jack_mixer_channel_t channel
)
332 channel_ptr
->abspeak
= 0;
333 channel_ptr
->NaN_detected
= false;
336 void channel_mute(jack_mixer_channel_t channel
)
338 channel_ptr
->muted
= true;
339 calc_channel_volumes(channel_ptr
);
342 void channel_unmute(jack_mixer_channel_t channel
)
344 channel_ptr
->muted
= false;
345 calc_channel_volumes(channel_ptr
);
348 void channel_solo(jack_mixer_channel_t channel
)
350 if (!channel_ptr
->soloed
)
352 channel_ptr
->soloed
= true;
353 channel_ptr
->mixer_ptr
->soloed_channels_count
++;
355 if (channel_ptr
->mixer_ptr
->soloed_channels_count
== 1)
357 calc_all_channel_volumes(channel_ptr
->mixer_ptr
);
361 calc_channel_volumes(channel_ptr
);
366 void channel_unsolo(jack_mixer_channel_t channel
)
368 if (channel_ptr
->soloed
)
370 channel_ptr
->soloed
= false;
371 channel_ptr
->mixer_ptr
->soloed_channels_count
--;
373 if (channel_ptr
->mixer_ptr
->soloed_channels_count
== 0)
375 calc_all_channel_volumes(channel_ptr
->mixer_ptr
);
379 calc_channel_volumes(channel_ptr
);
384 bool channel_is_muted(jack_mixer_channel_t channel
)
386 return channel_ptr
->muted
;
389 bool channel_is_soloed(jack_mixer_channel_t channel
)
391 return channel_ptr
->soloed
;
395 channel_set_midi_scale(
396 jack_mixer_channel_t channel
,
397 jack_mixer_scale_t scale
)
399 channel_ptr
->midi_scale
= scale
;
404 /* process input channels and mix them into main mix */
409 struct jack_mixer
* mixer_ptr
,
410 jack_nframes_t start
, /* index of first sample to process */
411 jack_nframes_t end
) /* index of sample to stop processing before */
414 struct list_head
* node_ptr
;
415 struct channel
* channel_ptr
;
416 jack_default_audio_sample_t frame_left
;
417 jack_default_audio_sample_t frame_right
;
419 list_for_each(node_ptr
, &mixer_ptr
->channels_list
)
421 channel_ptr
= list_entry(node_ptr
, struct channel
, siblings
);
423 for (i
= start
; i
< end
; i
++)
425 if (!FLOAT_EXISTS(channel_ptr
->left_buffer_ptr
[i
]))
427 channel_ptr
->NaN_detected
= true;
431 frame_left
= channel_ptr
->left_buffer_ptr
[i
] * channel_ptr
->volume_left
;
432 mixer_ptr
->main_mix_channel
.left_buffer_ptr
[i
] += frame_left
;
434 if (channel_ptr
->stereo
)
436 if (!FLOAT_EXISTS(channel_ptr
->right_buffer_ptr
[i
]))
438 channel_ptr
->NaN_detected
= true;
442 frame_right
= channel_ptr
->right_buffer_ptr
[i
] * channel_ptr
->volume_right
;
446 frame_right
= channel_ptr
->left_buffer_ptr
[i
] * channel_ptr
->volume_right
;
449 mixer_ptr
->main_mix_channel
.right_buffer_ptr
[i
] += frame_right
;
451 if (channel_ptr
->stereo
)
453 frame_left
= fabsf(frame_left
);
454 frame_right
= fabsf(frame_right
);
456 if (channel_ptr
->peak_left
< frame_left
)
458 channel_ptr
->peak_left
= frame_left
;
460 if (frame_left
> channel_ptr
->abspeak
)
462 channel_ptr
->abspeak
= frame_left
;
466 if (channel_ptr
->peak_right
< frame_right
)
468 channel_ptr
->peak_right
= frame_right
;
470 if (frame_right
> channel_ptr
->abspeak
)
472 channel_ptr
->abspeak
= frame_right
;
478 frame_left
= (fabsf(frame_left
) + fabsf(frame_right
)) / 2;
480 if (channel_ptr
->peak_left
< frame_left
)
482 channel_ptr
->peak_left
= frame_left
;
484 if (frame_left
> channel_ptr
->abspeak
)
486 channel_ptr
->abspeak
= frame_left
;
491 channel_ptr
->peak_frames
++;
492 if (channel_ptr
->peak_frames
>= PEAK_FRAMES_CHUNK
)
494 channel_ptr
->meter_left
= channel_ptr
->peak_left
;
495 channel_ptr
->peak_left
= 0.0;
497 if (channel_ptr
->stereo
)
499 channel_ptr
->meter_right
= channel_ptr
->peak_right
;
500 channel_ptr
->peak_right
= 0.0;
503 channel_ptr
->peak_frames
= 0;
508 /* process main mix channel */
509 for (i
= start
; i
< end
; i
++)
511 mixer_ptr
->main_mix_channel
.left_buffer_ptr
[i
] *= mixer_ptr
->main_mix_channel
.volume_left
;
512 mixer_ptr
->main_mix_channel
.right_buffer_ptr
[i
] *= mixer_ptr
->main_mix_channel
.volume_right
;
514 frame_left
= fabsf(mixer_ptr
->main_mix_channel
.left_buffer_ptr
[i
]);
515 if (mixer_ptr
->main_mix_channel
.peak_left
< frame_left
)
517 mixer_ptr
->main_mix_channel
.peak_left
= frame_left
;
519 if (frame_left
> mixer_ptr
->main_mix_channel
.abspeak
)
521 mixer_ptr
->main_mix_channel
.abspeak
= frame_left
;
525 frame_right
= fabsf(mixer_ptr
->main_mix_channel
.right_buffer_ptr
[i
]);
526 if (mixer_ptr
->main_mix_channel
.peak_right
< frame_right
)
528 mixer_ptr
->main_mix_channel
.peak_right
= frame_right
;
530 if (frame_right
> mixer_ptr
->main_mix_channel
.abspeak
)
532 mixer_ptr
->main_mix_channel
.abspeak
= frame_right
;
536 mixer_ptr
->main_mix_channel
.peak_frames
++;
537 if (mixer_ptr
->main_mix_channel
.peak_frames
>= PEAK_FRAMES_CHUNK
)
539 mixer_ptr
->main_mix_channel
.meter_left
= mixer_ptr
->main_mix_channel
.peak_left
;
540 mixer_ptr
->main_mix_channel
.peak_left
= 0.0;
542 mixer_ptr
->main_mix_channel
.meter_right
= mixer_ptr
->main_mix_channel
.peak_right
;
543 mixer_ptr
->main_mix_channel
.peak_right
= 0.0;
545 mixer_ptr
->main_mix_channel
.peak_frames
= 0;
553 update_channel_buffers(
554 struct channel
* channel_ptr
,
555 jack_nframes_t nframes
)
557 channel_ptr
->left_buffer_ptr
= jack_port_get_buffer(channel_ptr
->port_left
, nframes
);
559 if (channel_ptr
->stereo
)
561 channel_ptr
->right_buffer_ptr
= jack_port_get_buffer(channel_ptr
->port_right
, nframes
);
565 #define mixer_ptr ((struct jack_mixer *)context)
568 process(jack_nframes_t nframes
, void * context
)
571 struct list_head
* node_ptr
;
572 struct channel
* channel_ptr
;
573 #if defined(HAVE_JACK_MIDI)
574 jack_nframes_t event_count
;
575 jack_midi_event_t in_event
;
579 jack_nframes_t offset
;
581 update_channel_buffers(&mixer_ptr
->main_mix_channel
, nframes
);
583 list_for_each(node_ptr
, &mixer_ptr
->channels_list
)
585 channel_ptr
= list_entry(node_ptr
, struct channel
, siblings
);
587 update_channel_buffers(channel_ptr
, nframes
);
590 for (i
= 0 ; i
< nframes
; i
++)
592 mixer_ptr
->main_mix_channel
.left_buffer_ptr
[i
] = 0.0;
593 mixer_ptr
->main_mix_channel
.right_buffer_ptr
[i
] = 0.0;
598 #if defined(HAVE_JACK_MIDI)
599 midi_buffer
= jack_port_get_buffer(mixer_ptr
->port_midi_in
, nframes
);
600 event_count
= jack_midi_get_event_count(midi_buffer
);
602 for (i
= 0 ; i
< event_count
; i
++)
604 jack_midi_event_get(&in_event
, midi_buffer
, i
);
606 if (in_event
.size
!= 3 ||
607 (in_event
.buffer
[0] & 0xF0) != 0xB0 ||
608 in_event
.buffer
[1] > 127 ||
609 in_event
.buffer
[2] > 127)
614 assert(in_event
.time
< nframes
);
618 (unsigned int)(in_event
.buffer
[0] & 0x0F),
619 (unsigned int)in_event
.buffer
[1],
620 (unsigned int)in_event
.buffer
[2]);
622 channel_ptr
= mixer_ptr
->midi_cc_map
[in_event
.buffer
[1]].channel_ptr
;
624 /* if we have mapping for particular CC and MIDI scale is set for corresponding channel */
625 if (channel_ptr
!= NULL
&& channel_ptr
->midi_scale
!= NULL
)
627 assert(in_event
.time
>= offset
);
629 if (in_event
.time
> offset
)
631 mix(mixer_ptr
, offset
, in_event
.time
);
632 offset
= in_event
.time
;
635 if (mixer_ptr
->midi_cc_map
[in_event
.buffer
[1]].balance
)
637 byte
= in_event
.buffer
[2];
644 channel_ptr
->balance
= (float)byte
/ 63;
645 LOG_DEBUG("\"%s\" balance -> %f", channel_ptr
->name
, channel_ptr
->balance
);
649 channel_ptr
->volume
= db_to_value(scale_scale_to_db(channel_ptr
->midi_scale
, (double)in_event
.buffer
[2] / 127));
650 LOG_DEBUG("\"%s\" volume -> %f", channel_ptr
->name
, channel_ptr
->volume
);
653 calc_channel_volumes(channel_ptr
);
655 channel_ptr
->midi_modified
= true;
662 mix(mixer_ptr
, offset
, nframes
);
671 const char * jack_client_name_ptr
)
674 struct jack_mixer
* mixer_ptr
;
678 mixer_ptr
= malloc(sizeof(struct jack_mixer
));
679 if (mixer_ptr
== NULL
)
684 ret
= pthread_mutex_init(&mixer_ptr
->mutex
, NULL
);
690 INIT_LIST_HEAD(&mixer_ptr
->channels_list
);
692 mixer_ptr
->channels_count
= 0;
693 mixer_ptr
->soloed_channels_count
= 0;
695 for (i
= 0 ; i
< 128 ; i
++)
697 mixer_ptr
->midi_cc_map
[i
].channel_ptr
= NULL
;
700 mixer_ptr
->midi_cc_map
[7].channel_ptr
= &mixer_ptr
->main_mix_channel
;
701 mixer_ptr
->midi_cc_map
[7].balance
= false;
702 mixer_ptr
->main_mix_channel
.cc_map_volume_ptr_ptr
= &mixer_ptr
->midi_cc_map
[7].channel_ptr
;
704 mixer_ptr
->midi_cc_map
[8].channel_ptr
= &mixer_ptr
->main_mix_channel
;
705 mixer_ptr
->midi_cc_map
[8].balance
= true;
706 mixer_ptr
->main_mix_channel
.cc_map_balance_ptr_ptr
= &mixer_ptr
->midi_cc_map
[8].channel_ptr
;
708 LOG_DEBUG("Initializing JACK");
709 mixer_ptr
->jack_client
= jack_client_new(jack_client_name_ptr
);
710 if (mixer_ptr
->jack_client
== NULL
)
712 LOG_ERROR("Cannot create JACK client.");
713 LOG_NOTICE("Please make sure JACK daemon is running.");
714 goto exit_destroy_mutex
;
717 LOG_DEBUG("JACK client created");
719 LOG_DEBUG("Sample rate: %" PRIu32
, jack_get_sample_rate(mixer_ptr
->jack_client
));
721 mixer_ptr
->main_mix_channel
.mixer_ptr
= mixer_ptr
;
723 #if defined(HAVE_JACK_MIDI)
724 mixer_ptr
->port_midi_in
= jack_port_register(mixer_ptr
->jack_client
, "midi in", JACK_DEFAULT_MIDI_TYPE
, JackPortIsInput
, 0);
725 if (mixer_ptr
->port_midi_in
== NULL
)
727 LOG_ERROR("Cannot create JACK port");
732 mixer_ptr
->main_mix_channel
.port_left
= jack_port_register(mixer_ptr
->jack_client
, "main out L", JACK_DEFAULT_AUDIO_TYPE
, JackPortIsOutput
, 0);
733 if (mixer_ptr
->main_mix_channel
.port_left
== NULL
)
735 LOG_ERROR("Cannot create JACK port");
739 mixer_ptr
->main_mix_channel
.port_right
= jack_port_register(mixer_ptr
->jack_client
, "main out R", JACK_DEFAULT_AUDIO_TYPE
, JackPortIsOutput
, 0);
740 if (mixer_ptr
->main_mix_channel
.port_right
== NULL
)
742 LOG_ERROR("Cannot create JACK port");
746 mixer_ptr
->main_mix_channel
.stereo
= true;
748 mixer_ptr
->main_mix_channel
.name
= "MAIN";
750 mixer_ptr
->main_mix_channel
.volume
= 0.0;
751 mixer_ptr
->main_mix_channel
.balance
= 0.0;
752 mixer_ptr
->main_mix_channel
.muted
= false;
753 mixer_ptr
->main_mix_channel
.soloed
= false;
754 mixer_ptr
->main_mix_channel
.meter_left
= 0.0;
755 mixer_ptr
->main_mix_channel
.meter_right
= 0.0;
756 mixer_ptr
->main_mix_channel
.abspeak
= 0.0;
758 mixer_ptr
->main_mix_channel
.peak_left
= 0.0;
759 mixer_ptr
->main_mix_channel
.peak_right
= 0.0;
760 mixer_ptr
->main_mix_channel
.peak_frames
= 0;
762 mixer_ptr
->main_mix_channel
.NaN_detected
= false;
763 mixer_ptr
->main_mix_channel
.midi_modified
= false;
765 mixer_ptr
->main_mix_channel
.midi_scale
= NULL
;
767 calc_channel_volumes(&mixer_ptr
->main_mix_channel
);
769 ret
= jack_set_process_callback(mixer_ptr
->jack_client
, process
, mixer_ptr
);
772 LOG_ERROR("Cannot set JACK process callback");
776 ret
= jack_activate(mixer_ptr
->jack_client
);
779 LOG_ERROR("Cannot activate JACK client");
786 jack_client_close(mixer_ptr
->jack_client
); /* this should clear all other resources we obtained through the client handle */
789 pthread_mutex_destroy(&mixer_ptr
->mutex
);
798 #define mixer_ctx_ptr ((struct jack_mixer *)mixer)
804 LOG_DEBUG("Uninitializing JACK");
806 assert(mixer_ctx_ptr
->jack_client
!= NULL
);
808 jack_client_close(mixer_ctx_ptr
->jack_client
);
810 pthread_mutex_destroy(&mixer_ctx_ptr
->mutex
);
816 get_main_mix_channel(
819 return &mixer_ctx_ptr
->main_mix_channel
;
826 return mixer_ctx_ptr
->channels_count
;
832 const char * channel_name
,
835 struct channel
* channel_ptr
;
837 size_t channel_name_size
;
840 channel_ptr
= malloc(sizeof(struct channel
));
841 if (channel_ptr
== NULL
)
846 channel_ptr
->mixer_ptr
= mixer_ctx_ptr
;
848 channel_ptr
->name
= strdup(channel_name
);
849 if (channel_ptr
->name
== NULL
)
851 goto fail_free_channel
;
856 channel_name_size
= strlen(channel_name
);
858 port_name
= malloc(channel_name_size
+ 3);
859 if (port_name
== NULL
)
861 goto fail_free_channel_name
;
864 memcpy(port_name
, channel_name
, channel_name_size
);
865 port_name
[channel_name_size
] = ' ';
866 port_name
[channel_name_size
+1] = 'L';
867 port_name
[channel_name_size
+2] = 0;
869 channel_ptr
->port_left
= jack_port_register(channel_ptr
->mixer_ptr
->jack_client
, port_name
, JACK_DEFAULT_AUDIO_TYPE
, JackPortIsInput
, 0);
870 if (channel_ptr
->port_left
== NULL
)
872 goto fail_free_port_name
;
875 port_name
[channel_name_size
+1] = 'R';
877 channel_ptr
->port_right
= jack_port_register(channel_ptr
->mixer_ptr
->jack_client
, port_name
, JACK_DEFAULT_AUDIO_TYPE
, JackPortIsInput
, 0);
878 if (channel_ptr
->port_right
== NULL
)
880 goto fail_unregister_left_channel
;
885 channel_ptr
->port_left
= jack_port_register(channel_ptr
->mixer_ptr
->jack_client
, channel_name
, JACK_DEFAULT_AUDIO_TYPE
, JackPortIsInput
, 0);
886 if (channel_ptr
->port_left
== NULL
)
888 goto fail_free_channel_name
;
892 channel_ptr
->stereo
= stereo
;
894 channel_ptr
->volume
= 0.0;
895 channel_ptr
->balance
= 0.0;
896 channel_ptr
->muted
= false;
897 channel_ptr
->soloed
= false;
898 channel_ptr
->meter_left
= -1.0;
899 channel_ptr
->meter_right
= -1.0;
900 channel_ptr
->abspeak
= 0.0;
902 channel_ptr
->peak_left
= 0.0;
903 channel_ptr
->peak_right
= 0.0;
904 channel_ptr
->peak_frames
= 0;
906 channel_ptr
->NaN_detected
= false;
907 channel_ptr
->midi_modified
= false;
909 channel_ptr
->midi_scale
= NULL
;
911 calc_channel_volumes(channel_ptr
);
913 list_add_tail(&channel_ptr
->siblings
, &channel_ptr
->mixer_ptr
->channels_list
);
914 channel_ptr
->mixer_ptr
->channels_count
++;
916 for (i
= 11 ; i
< 128 ; i
++)
918 if (mixer_ctx_ptr
->midi_cc_map
[i
].channel_ptr
== NULL
)
920 mixer_ctx_ptr
->midi_cc_map
[i
].channel_ptr
= channel_ptr
;
921 mixer_ctx_ptr
->midi_cc_map
[i
].balance
= false;
922 channel_ptr
->cc_map_volume_ptr_ptr
= &mixer_ctx_ptr
->midi_cc_map
[i
].channel_ptr
;
924 LOG_NOTICE("New channel \"%s\" volume mapped to CC#%i", channel_name
, i
);
930 for (; i
< 128 ; i
++)
932 if (mixer_ctx_ptr
->midi_cc_map
[i
].channel_ptr
== NULL
)
934 mixer_ctx_ptr
->midi_cc_map
[i
].channel_ptr
= channel_ptr
;
935 mixer_ctx_ptr
->midi_cc_map
[i
].balance
= true;
936 channel_ptr
->cc_map_balance_ptr_ptr
= &mixer_ctx_ptr
->midi_cc_map
[i
].channel_ptr
;
938 LOG_NOTICE("New channel \"%s\" balance mapped to CC#%i", channel_name
, i
);
946 fail_unregister_left_channel
:
947 jack_port_unregister(channel_ptr
->mixer_ptr
->jack_client
, channel_ptr
->port_left
);
952 fail_free_channel_name
:
953 free(channel_ptr
->name
);