ita_modulita_control.m 23 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706
function varargout = ita_modulita_control(varargin)
%ITA_MODULITA_CONTROL - Send Settings to ModulITA Frontend
%  This function sends Midi Sysex Commands to the ModulITA frontend, also
%  known as Kuddelmuddel ITA (KMI) in Monkey Forest.
%
%  Syntax:
%      ita_modulita_control() - GUI
%      ita_modulita_control(ch_id, parameter, value)
%
%  Options:
%        'davalome' (1,xx)                              :      set output volume
%        'mode' ('norm','impref','ampref','lineref')    :      Predefined settings
%        'clock' ('hdsp',SamplingRate)                  :      hdsp sets soundcard to master clock
%                                                               if SamplingRate given, ModulITA is the master clock
%        'inputrange' (-40:10:60)                       :      input range for preamp select
%        'channel' (1..4, 'all')                        :      select the channel to modify
%        'input' ('xlr','gnd','ref','lemo')             :      select input type for preamp
%        'feed' ('off','pha','pol','p+p')               :      phantom/polarization voltage
%        'lemo' ('d14','s28','d44')                     :      polarization voltage type
%        'init' ('on')                                  :      Initialize ModulITA to good settings
%
%
%
%  If no parameters are specified ita_modulita_control() the gui
%  ita_modulita_control_gui will be automatically called
%
%   See also ita_modulita_control.
%
%   Reference page in Help browser
%        <a href="matlab:doc ita_modulita_control">doc ita_modulita_control</a>

% <ITA-Toolbox>
% This file is part of the application RoboAurelioModulITAControl for the ITA-Toolbox. All rights reserved.
% You can find the license for this m-file in the application folder.
% </ITA-Toolbox>


% Author: Pascal Dietrich -- Email: pdi@akustik.rwth-aachen.de
% Created:  11-Sep-2009 - pdi

if nargin == 0
    ita_modulitacontrol_gui()
    return;
end
if nargout >= 1
    varargout{1} = [];
end

%% Get ITA Toolbox preferences
verboseMode = false; %ita_preferences('verboseMode');
thisFuncStr = [upper(mfilename) ':'];
persistent oldSettings %store the values that have been sent to modulita

%% Argument parsing
narginchk(0,10);
sArgs        = struct('mode',[], 'clock',[],'inputrange',[],'channel','all','input',[],'feed',[],'lemo',[],'admode',[],...
    'init',false,'davolume',[],'adground2earth',[],'daground2earth',[],'adcoupling',[],'refbus2preamp',[],'preampcoupling',[],...
    'preampoffset',[],'phantomxlr',false,'parameterrequest',false,'getSettings','false');
[sArgs] = ita_parse_arguments(sArgs,varargin);

%% init modulita
if isempty(oldSettings) && ~sArgs.init %probably first start of the session or clear all has been used
    %just resend the init commando
    oldSettings.ch(1).inputrange = 1;
    oldSettings.mode = 'norm';
    ita_modulita_control('init');
end

% get midi port and open midi output stream
out_device_id = ita_preferences('out_midi_DeviceID');
if isempty(out_device_id) || out_device_id == -1
    errordlg('No valid Midi output device specified. Call ita_preferences().', 'ita_modulita_control - Midi Error');
    return;
end

%% generate message
preamble = '00 20 40 00 00 07';
message_hex = {};

if sArgs.parameterrequest
    % %     %dsp tools
    % %     preamble = '00 20 40 00 00 0c 00';
    % %     message_hex = {'00 02 00 00 00 00 00'};
    
    preamble = '00 20 40 00 00 0c';
    message_hex = {'08 09 ff ff 00 00'};
    
end

%% INIT commando to be sent to ModulITA/KMI
if sArgs.init
    
    %% conversion to Swen's Documentation
    %      hex2dec('50')-64
    % dec2hex(87+64)
    
    %      message_hex{end+1} = '04 00 00 00'; %default setup
    sArgs.clock = 'hdsp';
    %
    
    %%     message_hex{end+1} = '04 02 07 0f'; % ????
    % %     message_hex{end+1} = '04 03 07 0F';
    % %     message_hex{end+1} = '04 04 07 0F';
    % %     message_hex{end+1} = '05 00 00 00';
    % %     message_hex{end+1} = '05 01 00 00';
    % %     message_hex{end+1} = '05 02 00 00';
    % %     message_hex{end+1} = '05 03 00 00';
    
    
    
    %AD INPUT Init
    message_hex{end+1} = '05 0c 00 00';
    message_hex{end+1} = '05 0d 00 00';
    message_hex{end+1} = '05 0e 00 00';
    message_hex{end+1} = '05 0f 00 00';
    
    %%AD attenuation init to -19dB
    message_hex{end+1} = '06 00 00 00'; %ad1
    message_hex{end+1} = '06 01 00 00'; %ad3
    
    %%AD impedance INIT
    message_hex{end+1} = '06 02 00 00'; %ad0/1
    message_hex{end+1} = '06 03 00 00'; %ad2/3
    
    %%preamp offset  %off/sta/dyn  /0a/0b/1a/1b
    sArgs.preampoffset   = 'dyn';
    sArgs.inputrange     = 0;
    sArgs.inputfeed      = 'off';
    % preamp coupling AC/DC
    sArgs.preampcoupling = 'ac';
    sArgs.adcoupling     = 'dc';
    
    %AD OUT - Rout - ROUTING - STAY AWAY !!!
    message_hex{end+1} = '08 07 00 01';
    message_hex{end+1} = '08 08 00 02';
    message_hex{end+1} = '08 09 00 00';
    message_hex{end+1} = '08 0a 00 03';
    
    sArgs.refbus2preamp = 0;
    sArgs.mode         = 'normal';
    sArgs.input        = 'xlr';
    sArgs.feed         = 'off';
    
    % % message_hex{end+1} = '08 0d 00 00'; %Bekezy starten
    
    %amp out - LOAD - A: 10 ohm/external
    message_hex{end+1} = '09 02 00 01'; %A
    message_hex{end+1} = '09 03 00 01'; %A
    
    %amp out - GND - Ground/shunt
    message_hex{end+1} = '09 04 00 00'; %A
    message_hex{end+1} = '09 05 00 00'; %A
    
    %amp volume relative to DA - dBrel
    message_hex{end+1} = '09 06 05 06'; %A
    
    %amp out - off/da1/da2
    message_hex{end+1} = '09 07 00 02'; %pdi
    
    % % %     message_hex{end+1} = '04 00 00 00'; %default setup - store
    % % %     message_hex{end+1} = '05 01 00 00'; %default setup - setup Number 1
    
    % message_hex{end+1} = '05 05 0f 0f'; %security mode - for menu
    % message_hex{end+1} = '05 06 0f 0f'; %security mode - for menu
    sArgs.davolume = 0;
    sArgs.channel = 'all';
    sArgs.inputrange = 0;
end

%% Phantom and XLR shortcut
if sArgs.phantomxlr
    sArgs.input = 'xlr';
    sArgs.feed = 'pha';
end

%% **************************************************** pdi

%% AD coupling
if sArgs.adcoupling
    switch lower(sArgs.channel)
        case {'1',1}
            ch_hex{1} = '08';
        case {'2',2}
            ch_hex{1} = '09';
        case {'3',3}
            ch_hex{1} = '0a';
        case {'4',4}
            ch_hex{1} = '0b';
        case {'all'}
            ch_hex = {'08','09','0a','0b'};
        otherwise
            error([thisFuncStr 'Channel setting unknown.'])
    end
    %     message_hex{end+1} = '05 08 00 01'; %AD-coupling 0 : dc 1 : ac ch:ad0
    switch lower(sArgs.adcoupling)
        case {'ac'}
            adda_hex = '01';
        case {'dc'}
            adda_hex = '00';
        otherwise
            error([thisFuncStr 'AD coupling mode unknown'])
    end
    for ch_idx = 1:length(ch_hex)
        message_hex{end+1} = ['05 ' ch_hex{ch_idx} ' 00 ' adda_hex]; %#ok<AGROW> %AD-coupling 0 : dc 1 : ac ch:ad0
    end
end

%% Preamp coupling
if sArgs.preampcoupling
    switch lower(sArgs.channel)
        case {'1',1}
            ch_hex{1} = '01';
        case {'2',2}
            ch_hex{1} = '02';
        case {'3',3}
            ch_hex{1} = '03';
        case {'4',4}
            ch_hex{1} = '04';
        case {'all'}
            ch_hex = {'01','02','03','04'};
        otherwise
            error([thisFuncStr 'Channel setting unknown.'])
    end
    switch lower(sArgs.preampcoupling)
        case {'ac'}
            adda_hex = '00';
        case {'dc'}
            adda_hex = '01';
        otherwise
            error([thisFuncStr 'Preamp coupling mode unknown'])
    end
    for ch_idx = 1:length(ch_hex)
        message_hex{end+1} = ['07 ' ch_hex{ch_idx} ' 00 ' adda_hex]; %#ok<AGROW> %AD-coupling 0 : dc 1 : ac ch:ad0
    end
end

%% Preamp offset
if ~isempty(sArgs.preampoffset)
    switch lower(sArgs.channel)
        case {'1',1}
            ch_hex{1} = '09';
        case {'2',2}
            ch_hex{1} = '0a';
        case {'3',3}
            ch_hex{1} = '0b';
        case {'4',4}
            ch_hex{1} = '0c';
        case {'all'}
            ch_hex = {'09','0a','0b','0c'};
        otherwise
            error([thisFuncStr 'Channel setting unknown.'])
    end
    switch lower(sArgs.preampoffset)
        case {'off',0}
            adda_hex = '00';
        case {'sta','static'}
            adda_hex = '01';
        case {'dyn','dynamic'}
            adda_hex = '02';
            
        otherwise
            error([thisFuncStr 'Preamp offset mode unknown'])
    end
    %     message_hex{end+1} = '06 09 00 02';
    %     message_hex{end+1} = '06 0a 00 02';
    %     message_hex{end+1} = '06 0b 00 02';
    %     message_hex{end+1} = '06 0c 00 02';
    for ch_idx = 1:length(ch_hex)
        message_hex{end+1} = ['06 ' ch_hex{ch_idx} ' 00 ' adda_hex]; %#ok<AGROW> %AD-coupling 0 : dc 1 : ac ch:ad0
    end
end

%% **************************************************** pdi
%% DA Volume in dBFS
if ~isempty(sArgs.davolume)
    sArgs.davolume = max(min(sArgs.davolume,0),-127);
    davol_hex = ita_angle2str(dec2hex(sArgs.davolume +127),2);
    message_hex{end+1} = ['04 01 0' davol_hex(1) '0' davol_hex(2)]; %da volume -127
    oldSettings.davolume = sArgs.davolume;
end
%% AD/DA ground to earth
if ~isempty(sArgs.adground2earth)
    message_hex{end+1} = ['0A 00 00 0' num2str(sArgs.adground2earth)];
end
if ~isempty(sArgs.daground2earth)
    message_hex{end+1} = ['0A 01 00 0' num2str(sArgs.daground2earth)];
end

%% **************************************************** pdi
%% clock origin HDSP
if sArgs.clock
    if isnumeric(sArgs.clock), sArgs.clock = num2str(sArgs.clock); end
    switch lower(sArgs.clock)
        case 'hdsp'
            %hdsp
            message_hex{end+1} = '07 0D 00 04';
        case {'32k','32000'}
            %32k - kmi is master
            message_hex{end+1} = '07 0D 00 00';
        case {'44k','44100'}
            %44k
            message_hex{end+1} = '07 0D 00 01';
        case {'48k','48000'}
            %48k
            message_hex{end+1} = '07 0D 00 02';
        case {'96k','96000'}
            %96k
            message_hex{end+1} = '07 0D 00 03';
        otherwise
            error([thisFuncStr 'clock setting unknown.'])
    end
end

%% **************************************************** pdi
%% mode - AD input from reference line
if sArgs.mode
    switch lower(sArgs.mode)
        case {'normal','norm'}
            oldSettings.mode = 'norm';
            message_hex{end+1} = '06 05 00 02';
            message_hex{end+1} = '06 06 00 02';
            message_hex{end+1} = '06 07 00 02';
            message_hex{end+1} = '06 08 00 00';
            message_hex{end+1} = '09 02 00 01';
            message_hex{end+1} = '09 03 00 01';
        case {'imp','impedance'}
            oldSettings.mode = 'imp';
            message_hex{end+1} = '05 0C 00 00';
            message_hex{end+1} = '05 0D 00 01';
            message_hex{end+1} = '05 0E 00 01';
            message_hex{end+1} = '05 0F 00 00';
            message_hex{end+1} = '06 02 00 01';
            message_hex{end+1} = '06 03 00 01';
            message_hex{end+1} = '06 04 00 00';
            message_hex{end+1} = '06 05 00 00';
            message_hex{end+1} = '06 06 00 00';
            message_hex{end+1} = '06 07 00 00';
            message_hex{end+1} = '08 07 00 02';
            message_hex{end+1} = '08 08 00 03';
            message_hex{end+1} = '08 09 00 02';
            message_hex{end+1} = '08 0A 00 03';
            message_hex{end+1} = '09 02 00 01';
            message_hex{end+1} = '09 03 00 01';
            message_hex{end+1} = '09 04 00 01';
            message_hex{end+1} = '09 05 00 01';
            
        case {'impref'}
            oldSettings.mode = 'impref';
            % % imp ref
            % F0 00 20 40 00 00 07 00  00 09 02 00 00 00 00 00  |   @            |
            % 10  00 09 03 00 00 00 00 F7
            message_hex{end+1} = '09 02 00 00';
            message_hex{end+1} = '09 03 00 00';
            
        case {'lineref'}
            oldSettings.mode = 'lineref';
            % F0 00 20 40 00 00 07 00  00 05 0C 00 01 00 00 00
            % 00 05 0D 00 00 00 00 00  00 05 0E 00 00 00 00 00
            % 00 05 0F 00 01 00 00 00  00 06 02 00 00 00 00 00
            % 00 06 03 00 00 00 00 00  00 06 04 00 03 00 00 00
            % 00 06 06 00 03 00 00 00  00 06 08 00 01 00 00 00
            % 00 08 07 00 01 00 00 00  00 08 08 00 00 00 00 00
            % 00 08 09 00 01 00 00 00  00 08 0A 00 00 00 00 00
            % 00 09 02 00 01 00 00 00  00 09 03 00 01 00 00 00
            % 00 09 04 00 00 00 00 00  00 09 05 00 00 00 00
            
            message_hex{end+1} = '05 0C 00 01';
            message_hex{end+1} = '05 0D 00 00';
            message_hex{end+1} = '05 0E 00 00';
            message_hex{end+1} = '05 0F 00 01';
            message_hex{end+1} = '06 02 00 00';
            message_hex{end+1} = '06 03 00 00';
            message_hex{end+1} = '06 04 00 03';
            message_hex{end+1} = '06 06 00 03';
            message_hex{end+1} = '06 08 00 01';
            message_hex{end+1} = '08 07 00 01';
            message_hex{end+1} = '08 08 00 00';
            message_hex{end+1} = '08 09 00 01';
            message_hex{end+1} = '08 0A 00 00';
            message_hex{end+1} = '09 02 00 01';
            message_hex{end+1} = '09 03 00 01';
            message_hex{end+1} = '09 04 00 00';
            message_hex{end+1} = '09 05 00 00';
            sArgs.input = 'ref';
            sArgs.channel = 'all';
            sArgs.refbus2preamp = '1a';
        case {'ampref'}
            oldSettings.mode = 'ampref';
            %% amp ref
            % F0 00 20 40 00 00 07 00  00 06 08 00 05 00 00 F7
            message_hex{end+1} = '06 08 00 05';
            
            sArgs.input = 'ref';
            sArgs.channel = 'all';
            
        otherwise
            error([thisFuncStr 'clock setting unknown.'])
    end
end

%% Input Range
if ~isempty(sArgs.inputrange)
    %     -40 -> 0
    %     60 -> 6
    % % %% Input Range
    % % %                                          ch    sens
    % % % ch: 09 0A 0B 0C in SysEx
    % % % ch: 0a 0b 1a 1b
    switch lower(sArgs.channel)
        case {'2','0b',2}
            ch_hex{1} = '09';
            ch_idx = 2;
        case {'4','1b',4}
            ch_idx = 4;
            ch_hex{1} = '0a';
        case {'1','1a',1}
            ch_idx = (1);
            ch_hex{1} = '0b';
        case {'3','0a',3}
            ch_idx = 3;
            ch_hex{1} = '0c';
        case {'all'}
            ch_idx = 1:4;
            ch_hex = {'09','0a','0b','0c'};
        otherwise
            error([thisFuncStr 'Channel unknown.'])
    end
    sArgs.inputrange = max(min(sArgs.inputrange,40),-60);
    range_hex = ['0' dec2hex(abs(sArgs.inputrange/10-4))];
    
    for ch_jdx = 1:length(ch_hex)
        message_hex{end+1} = ['07 ' ch_hex{ch_jdx} ' 00 ' range_hex]; %#ok<AGROW>
        oldSettings.ch(ch_idx(ch_jdx)).inputrange = sArgs.inputrange;
    end    % %
end

%% **************************************************** pdi
%% AD mode
if sArgs.admode
    switch lower(sArgs.admode)
        case {'normal','norm','2channel'}
            message_hex{end+1} = '05 0C 00 00';
            message_hex{end+1} = '05 0F 00 00';
            message_hex{end+1} = '08 08 00 02';
            message_hex{end+1} = '08 09 00 00';
            message_hex{end+1} = '08 0A 00 03';
            message_hex{end+1} = '08 0B 00 00';
            message_hex{end+1} = '08 0C 00 00';
            
            
        case {'2-range','2range','stacked'}
            message_hex{end+1} = '05 0c 00 01';
            message_hex{end+1} = '05 0F 00 01';
            message_hex{end+1} = '06 00 00 01';
            message_hex{end+1} = '06 01 00 01';
            message_hex{end+1} = '08 08 00 00';
            
            message_hex{end+1} = '08 09 00 01';
            message_hex{end+1} = '08 0A 00 00';
            message_hex{end+1} = '08 0B 00 01';
            message_hex{end+1} = '08 0C 00 01';
            
            
        case {'parmono','par.mono','parallel'}
            message_hex{end+1} = '06 00 00 00';
            message_hex{end+1} = '06 01 00 00';
            message_hex{end+1} = '08 0B 00 02';
            message_hex{end+1} = '08 0C 00 02';
            
        otherwise
            error([thisFuncStr 'ADmode setting unknown.'])
    end
end %pdi

%% **************************************************** pdi
%% Input selection
if ~isempty(sArgs.input)
    switch lower(sArgs.channel)
        case {'2','0a',2}
            ch_hex{1} = '04';
            ch_idx = 2;
        case {'4','0b',4}
            ch_hex{1} = '05';
            ch_idx = 4;
        case {'1','1a',1}
            ch_hex{1} = '06';
            ch_idx = 1;
        case {'3','1b',3}
            ch_hex{1} = '07';
            ch_idx = 3;
        case {'all'}
            ch_hex = {'04','05','06','07'};
            ch_idx = 1:4;
        otherwise
            error([thisFuncStr 'Channel setting unknown.'])
    end
    
    switch lower(sArgs.input)
        
        case {'gnd','off',0}
            input_hex = '00';
            sArgs.input = 'gnd';
        case {'lemo','lem'}
            input_hex = '01';
            sArgs.input = 'lemo';
        case {'xlr'}
            input_hex = '02';
            sArgs.input = 'xlr';
        case {'ref','reference'}
            sArgs.input = 'ref';
            input_hex = '03';
        otherwise
            error([thisFuncStr 'Input setting unknown.'])
    end
    
    % % %     message_hex{end+1} = '06 04 00 04'; %ad3 GND/Lem/XLR/REF
    for ch_jdx = 1:length(ch_hex)
        message_hex{end+1} = ['06 ' ch_hex{ch_jdx} ' 00 ' input_hex]; %#ok<AGROW>
        oldSettings.ch(ch_idx(ch_jdx)).inputselect = sArgs.input;
    end
end

%% **************************************************** pdi
%% phantom power mode
if ~isempty(sArgs.feed)
    % % %     %% phantom
    % % %     %xlr 48v ch1 on, lemo off lemo sup 14V
    % % %
    % % %      06 0F 00 02 on
    % % %      06 0F 00 00 off
    % % %      lemo power
    % % %      06 0F 00 01 on
    % % %      06 0F 00 00 off
    % % %      %lemo on, xlr on
    % % %      06 0F 00 03
    % % %
    % % %      %ch2
    % % %      06 0D 00 02
    % % %      %ch3
    % % %      07 00 00 02
    % % %      %ch 4
    % % %      06 0E 00 00
    switch lower(sArgs.channel)
        case {'1','0a',1} %3
            ch_hex = {'06 0f'};
            ch_idx = 1;
        case {'2','0b',2} %4
            ch_hex = {'06 0d'};
            ch_idx = 2;
        case {'3','0c',3} %1
            ch_hex = {'07 00'};
            ch_idx = 3;
        case {'4','0d',4} %2
            ch_hex = {'06 0e'};
            ch_idx = 4;
        case {'all'}
            ch_hex = {'06 0f','06 0d','07 00','06 0e'};
            ch_idx = 1:4;
        otherwise
            error([thisFuncStr 'Channel setting unknown.'])
    end
    switch lower(sArgs.feed)
        case {'off',0}
            feed_hex = '00';
        case {'pol','lemo'}
            feed_hex = '01';
        case {'pha','xlr'}
            feed_hex = '02';
        case {'p+p',1}
            feed_hex = '03';
        otherwise
            error([thisFuncStr 'Feed-Voltage/Power setting unknown.'])
    end
    for ch_jdx = 1:length(ch_hex)
        message_hex{end+1} = [ch_hex{ch_jdx} ' 00 ' feed_hex]; %#ok<AGROW>
        oldSettings.ch(ch_idx(ch_jdx)).inputfeed = sArgs.feed;
    end
end

%% **************************************************** pdi
%% lemo feed
% % % % xlr 48 off; lemo pol off; lemo supp 14; input select xlr; (coupling ac)?
if sArgs.lemo
    switch lower(sArgs.channel)
        case {'1','0a',1}
            ch_hex = {'07 07'};
        case {'2','0b',2}
            ch_hex = {'07 05'};
        case {'3','0c',3}
            ch_hex = {'07 08'};
        case {'4','0d',4}
            ch_hex = {'07 06'};
        case {'all'}
            ch_hex = {'07 07','07 05','07 08','07 06'};
        otherwise
            error([thisFuncStr 'Channel setting unknown.'])
    end
    switch lower(sArgs.lemo)
        case {'d14'}
            feed_hex = '02';
        case {'s28'}
            feed_hex = '01';
        case {'d44','normal',1}
            feed_hex = '00';
        otherwise
            error([thisFuncStr 'Feed-Voltage/Power setting unknown.'])
    end
    
    
    for ch_idx = 1:length(ch_hex)
        message_hex{end+1} = [ch_hex{ch_idx} ' 00 ' feed_hex]; %#ok<AGROW>
    end
    
end

%% refbus2preamp
if ~isempty(sArgs.refbus2preamp)
    switch lower(sArgs.refbus2preamp)
        case {0}
            refbus_hex = '00';
        case {'0a'}
            refbus_hex = '01';
        case {'0b'}
            refbus_hex = '02';
        case {'1a'}
            refbus_hex = '03';
        case {'1b'}
            refbus_hex = '04';
        case {'ampa'}
            refbus_hex = '05';
        case {'ampb'}
            refbus_hex = '06';
            
        otherwise
            error([thisFuncStr 'Refbus2Preamp setting unknown.'])
            
    end
    % off/0a/0b/1a/1b/ampA/ampB/
    message_hex{end+1} = ['06 08 00 ' refbus_hex]; %referenz_bus preamp off
end

%% **************************************************** pdi
%% generate and send final message
if ~sArgs.parameterrequest
    message_hex_complete = message_hex;
    packetsize = 100; %pdi: was 15 before
    for message_idx = 1:packetsize+1:length(message_hex_complete)
        message_hex = message_hex_complete( message_idx:min(length(message_hex_complete),message_idx+packetsize) );
        
        final_message = preamble;
        for idx = 1:length(message_hex)
            final_message = [final_message '00 00' message_hex{idx} '00 00']; %#ok<AGROW>
        end
        %delete spaces
        final_message = final_message(final_message ~= ' ');
        final_message_dec = [];
        for idx=1:2:length(final_message)
            if verboseMode %show message in blocks
                fprintf([final_message(idx:idx+1) ' ']);
                if ~mod(idx+3,16), fprintf('  '), end;
                if ~mod(idx+3,32), fprintf('\n'), end;
            end
            final_message_dec = [final_message_dec hex2dec(final_message(idx:idx+1))]; %#ok<AGROW>
        end
        
        %% send sysex
        sysex = [240 final_message_dec 247]; %pre- post- ampel
        ita_midi(sysex,ita_preferences('out_midi_DeviceID'));
        
    end
else %parameterrequest
    
%     final_message = preamble;
%     for idx = 1:length(message_hex)
%         final_message = [final_message '' message_hex{idx} '']; %#ok<AGROW>
%     end
%     %delete spaces
%     final_message = final_message(final_message ~= ' ');
%     final_message_dec = [];
%     if verboseMode
%         disp('******************************************************')
%         fprintf('F0 ')
%     end;
%     for idx=1:2:length(final_message)
%         if verboseMode %show message in blocks
%             fprintf([final_message(idx:idx+1) ' ']);
%             if ~mod(idx+3,16), fprintf('  '), end;
%             if ~mod(idx+3,32), fprintf('\n'), end;
%         end
%         final_message_dec = [final_message_dec hex2dec(final_message(idx:idx+1))]; %#ok<AGROW>
%     end
%     if verboseMode
%         fprintf('F7\n')
%         disp('******************************************************')
%     end;
%     
%     m__old__midi('write_sysex',final_message_dec,1);
end

if sArgs.getSettings
    varargout{1} = oldSettings;
elseif nargout
    varargout{1} = true; %run successful
end
%end function
end