<effect>
  <name>Xpan</name>
  <enabled>true</enabled>
  <numIns>2</numIns>
  <numOuts>2</numOuts>
  <code>if (&lt;XpanON&gt; == 1) then
    if &lt;Xpan_combine to mono&gt; == 1 then
        ain = (ain1 + ain2) * .75                                                    ; when mono sent across stereo image
        aout1,aout2	pan2	ain, &lt;Xpan_panning&gt;, i(&lt;Xpan_mode&gt;)
    else
        if &lt;Xpan_swap channels&gt; == 0 then            
            aout1   =   ain1
            aout2   =   ain2
        else
            aout1   =   ain2                                                        ; left and right channels are swapped
            aout2   =   ain1
        endif
        if &lt;Xpan_MS stereo&gt; == 1 then
            aout1, aout2 stereoRotate ain1, ain2, &lt;Xpan_MS rotate&gt; ; rotate 45 degrees to the right
        endif
    endif
    aout1   *=   &lt;Xpan_gain Left&gt;                                                             ; apply gain to channel
    aout2   *=   &lt;Xpan_gain Right&gt;
else
    aout1   =   ain1
    aout2   =   ain2
endif</code>
  <comments>
DESCRIPTION:

small tool - but very handy - that uses the opcode pan2. pan2 offers 4 different ways of panning solutions - see manual.
The incoming signal can be either mono or stereo.


CONTROLLERS:

ON/OFF          -       bypass
combine to mono -       If the signal is stereo, it can be made a mono one. 
panning         -       pan the mono signal
mode            -       pan the mono signal according to different panning laws
swap Left/Right channel - exactly that
MS stereo       -       use the MS stereo formula on the stereo signal
MS Rotate       -       the angle of rotation in degrees, usually in the range of -45 to +45. Negative values result in a rotation rightward. Positive values rotate leftward.
Left/Right      -       output gain for Left and Right channel

---

version 1.22, July 2020
- added BSB information comments

version 1.21, May 2020
- added comments on controllers

version 1.2, February 2019
- included MS stereo option for alternative panning handling, using the UDO from http://www.csounds.com/udo/displayOpcode.php?opcode_id=45, 
created by Joseph Anderson and Matthew Ingalls

version 1.1, February 2019
- added stereo option with swap channels
- added channel gain

version 1, november 2017
- mixes the left and right signal so it can be panned in a stereo image  (by Menno Knevel)</comments>
  <opcodeList>
    <udo>
      <opcodeName>stereoRotate</opcodeName>
      <outTypes>aa</outTypes>
      <inTypes>aak</inTypes>
      <codeBody>ainl, ainr, ktheta xin

	; constants
	ipi		=	3.141592653589793
	iradfac	=	ipi/180

	;compute coeffs
	ktheta	=	iradfac*ktheta
	kstheta	=	sin(ktheta)
	kctheta	=	cos(ktheta)
	
	;Do Rotate
	aoutl		=	kctheta*ainl + kstheta*ainr
	aoutr		=	-kstheta*ainl + kctheta*ainr
xout    aoutl, aoutr</codeBody>
      <comments></comments>
    </udo>
  </opcodeList>
  <graphicInterface editEnabled='false'>
    <gridSettings>
      <width>5</width>
      <height>5</height>
      <gridStyle>DOT</gridStyle>
      <snapGridEnabled>true</snapGridEnabled>
    </gridSettings>
    <bsbObject type='blue.orchestra.blueSynthBuilder.BSBGroup'>
      <objectName></objectName>
      <x>0</x>
      <y>0</y>
      <groupName>Group</groupName>
      <backgroundColor>0x00000033</backgroundColor>
      <borderColor>0x000000ff</borderColor>
      <labelTextColor>0xffffffff</labelTextColor>
      <titleEnabled>true</titleEnabled>
      <width>20</width>
      <height>20</height>
      <bsbObject type='blue.orchestra.blueSynthBuilder.BSBCheckBox'>
        <objectName>XpanON</objectName>
        <x>0</x>
        <y>0</y>
        <comment>bypass</comment>
        <automationAllowed>true</automationAllowed>
        <label/>
        <selected>true</selected>
        <randomizable>true</randomizable>
      </bsbObject>
      <bsbObject type='blue.orchestra.blueSynthBuilder.BSBGroup'>
        <objectName></objectName>
        <x>10</x>
        <y>10</y>
        <groupName>XPan</groupName>
        <backgroundColor>0x4d8080ff</backgroundColor>
        <borderColor>0x000000ff</borderColor>
        <labelTextColor>0xffffffff</labelTextColor>
        <titleEnabled>false</titleEnabled>
        <width>20</width>
        <height>72</height>
        <bsbObject type='blue.orchestra.blueSynthBuilder.BSBGroup'>
          <objectName></objectName>
          <x>180</x>
          <y>10</y>
          <groupName>if stereo input</groupName>
          <backgroundColor>0x00000033</backgroundColor>
          <borderColor>0x1a4d4dff</borderColor>
          <labelTextColor>0xffffffff</labelTextColor>
          <titleEnabled>true</titleEnabled>
          <width>20</width>
          <height>20</height>
          <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel' version='2'>
            <objectName></objectName>
            <x>84</x>
            <y>48</y>
            <label>l</label>
            <font>
              <name>System Regular</name>
              <size>12.0</size>
            </font>
          </bsbObject>
          <bsbObject type='blue.orchestra.blueSynthBuilder.BSBHSlider' version='2'>
            <objectName>Xpan_MS rotate</objectName>
            <x>10</x>
            <y>50</y>
            <comment>the angle of rotation in degrees, usually in the range of -45 to +45. Negative values result in a rotation rightward. Positive values rotate leftward.</comment>
            <automationAllowed>true</automationAllowed>
            <minimum>-45.0</minimum>
            <maximum>45.0</maximum>
            <bdresolution>0.1</bdresolution>
            <value>0.0</value>
            <sliderWidth>150</sliderWidth>
            <randomizable>true</randomizable>
            <valueDisplayEnabled>true</valueDisplayEnabled>
          </bsbObject>
          <bsbObject type='blue.orchestra.blueSynthBuilder.BSBCheckBox'>
            <objectName>Xpan_swap channels</objectName>
            <x>10</x>
            <y>10</y>
            <comment>exactly that</comment>
            <automationAllowed>true</automationAllowed>
            <label>swap Left/Right channel</label>
            <selected>false</selected>
            <randomizable>true</randomizable>
          </bsbObject>
          <bsbObject type='blue.orchestra.blueSynthBuilder.BSBCheckBox'>
            <objectName>Xpan_MS stereo</objectName>
            <x>10</x>
            <y>30</y>
            <comment>use the MS stereo formula on the stereo signal</comment>
            <automationAllowed>true</automationAllowed>
            <label>MS stereo</label>
            <selected>false</selected>
            <randomizable>true</randomizable>
          </bsbObject>
        </bsbObject>
        <bsbObject type='blue.orchestra.blueSynthBuilder.BSBVSlider' version='2'>
          <objectName>Xpan_gain Right</objectName>
          <x>435</x>
          <y>10</y>
          <comment>output gain for Right channel</comment>
          <automationAllowed>true</automationAllowed>
          <minimum>0.0</minimum>
          <maximum>1.0</maximum>
          <bdresolution>0.1</bdresolution>
          <value>1.0</value>
          <sliderHeight>90</sliderHeight>
          <randomizable>true</randomizable>
          <valueDisplayEnabled>false</valueDisplayEnabled>
        </bsbObject>
        <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel' version='2'>
          <objectName></objectName>
          <x>435</x>
          <y>105</y>
          <label>Right</label>
          <font>
            <name>System Regular</name>
            <size>12.0</size>
          </font>
        </bsbObject>
        <bsbObject type='blue.orchestra.blueSynthBuilder.BSBGroup'>
          <objectName></objectName>
          <x>10</x>
          <y>10</y>
          <groupName>if mono input</groupName>
          <backgroundColor>0x00000033</backgroundColor>
          <borderColor>0x1a4d4dff</borderColor>
          <labelTextColor>0xffffffff</labelTextColor>
          <titleEnabled>true</titleEnabled>
          <width>20</width>
          <height>20</height>
          <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel' version='2'>
            <objectName></objectName>
            <x>83</x>
            <y>27</y>
            <label>l</label>
            <font>
              <name>System Regular</name>
              <size>12.0</size>
            </font>
          </bsbObject>
          <bsbObject type='blue.orchestra.blueSynthBuilder.BSBDropdown' version='2'>
            <objectName>Xpan_mode</objectName>
            <x>30</x>
            <y>55</y>
            <comment>pan the mono signal according to different panning laws</comment>
            <automationAllowed>true</automationAllowed>
            <selectedIndex>1</selectedIndex>
            <fontSize>12</fontSize>
            <randomizable>true</randomizable>
            <bsbDropdownItemList>
              <bsbDropdownItem uniqueId='-1630463723'>
                <name>equal power</name>
                <value>0</value>
              </bsbDropdownItem>
              <bsbDropdownItem uniqueId='-1630463722'>
                <name>square root</name>
                <value>1</value>
              </bsbDropdownItem>
              <bsbDropdownItem uniqueId='-1630463721'>
                <name>simple linear</name>
                <value>2</value>
              </bsbDropdownItem>
              <bsbDropdownItem uniqueId='-1630463720'>
                <name>alt. eq. power </name>
                <value>3</value>
              </bsbDropdownItem>
            </bsbDropdownItemList>
          </bsbObject>
          <bsbObject type='blue.orchestra.blueSynthBuilder.BSBHSlider' version='2'>
            <objectName>Xpan_panning</objectName>
            <x>10</x>
            <y>30</y>
            <comment>pan the mono signal</comment>
            <automationAllowed>true</automationAllowed>
            <minimum>0.0</minimum>
            <maximum>1.0</maximum>
            <bdresolution>0.05</bdresolution>
            <value>0.5</value>
            <sliderWidth>150</sliderWidth>
            <randomizable>true</randomizable>
            <valueDisplayEnabled>false</valueDisplayEnabled>
          </bsbObject>
          <bsbObject type='blue.orchestra.blueSynthBuilder.BSBCheckBox'>
            <objectName>Xpan_combine to mono</objectName>
            <x>10</x>
            <y>10</y>
            <comment>If the signal is stereo, it can be made a mono one.</comment>
            <automationAllowed>true</automationAllowed>
            <label>combine to mono</label>
            <selected>false</selected>
            <randomizable>true</randomizable>
          </bsbObject>
        </bsbObject>
        <bsbObject type='blue.orchestra.blueSynthBuilder.BSBLabel' version='2'>
          <objectName></objectName>
          <x>405</x>
          <y>105</y>
          <label>Left</label>
          <font>
            <name>System Regular</name>
            <size>12.0</size>
          </font>
        </bsbObject>
        <bsbObject type='blue.orchestra.blueSynthBuilder.BSBVSlider' version='2'>
          <objectName>Xpan_gain Left</objectName>
          <x>405</x>
          <y>10</y>
          <comment>output gain for Left channel</comment>
          <automationAllowed>true</automationAllowed>
          <minimum>0.0</minimum>
          <maximum>1.0</maximum>
          <bdresolution>0.1</bdresolution>
          <value>1.0</value>
          <sliderHeight>90</sliderHeight>
          <randomizable>true</randomizable>
          <valueDisplayEnabled>false</valueDisplayEnabled>
        </bsbObject>
      </bsbObject>
    </bsbObject>
  </graphicInterface>
  <parameterList>
    <parameter uniqueId='-1630463724' name='Xpan_panning' label='' min='0.0' max='1.0' bdresolution='0.05' automationEnabled='false' value='0.5'>
      <line name='' version='2' max='1.0' min='0.0' bdresolution='0.05' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='0.5'/>
      </line>
    </parameter>
    <parameter uniqueId='-1630463718' name='Xpan_mode' label='' min='0.0' max='3.0' bdresolution='1' automationEnabled='false' value='1.0'>
      <line name='' version='2' max='3.0' min='0.0' bdresolution='1' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='1.0'/>
      </line>
    </parameter>
    <parameter uniqueId='-1560515175' name='Xpan_gain Right' label='' min='0.0' max='1.0' bdresolution='0.1' automationEnabled='false' value='1.0'>
      <line name='' version='2' max='1.0' min='0.0' bdresolution='0.1' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='1.0'/>
      </line>
    </parameter>
    <parameter uniqueId='-1560515173' name='Xpan_gain Left' label='' min='0.0' max='1.0' bdresolution='0.1' automationEnabled='false' value='1.0'>
      <line name='' version='2' max='1.0' min='0.0' bdresolution='0.1' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='1.0'/>
      </line>
    </parameter>
    <parameter uniqueId='-1560515171' name='Xpan_swap channels' label='' min='0.0' max='1.0' bdresolution='1' automationEnabled='false' value='0.0'>
      <line name='' version='2' max='1.0' min='0.0' bdresolution='1' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='0.0'/>
      </line>
    </parameter>
    <parameter uniqueId='-1560515165' name='Xpan_combine to mono' label='' min='0.0' max='1.0' bdresolution='1' automationEnabled='false' value='0.0'>
      <line name='' version='2' max='1.0' min='0.0' bdresolution='1' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='0.0'/>
      </line>
    </parameter>
    <parameter uniqueId='-1560514717' name='Xpan_MS rotate' label='' min='-45.0' max='45.0' bdresolution='0.1' automationEnabled='false' value='0.0'>
      <line name='' version='2' max='45.0' min='-45.0' bdresolution='0.1' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='0.0'/>
      </line>
    </parameter>
    <parameter uniqueId='-1560514715' name='Xpan_MS stereo' label='' min='0.0' max='1.0' bdresolution='1' automationEnabled='false' value='0.0'>
      <line name='' version='2' max='1.0' min='0.0' bdresolution='1' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='0.0'/>
      </line>
    </parameter>
    <parameter uniqueId='-104104333' name='XpanON' label='' min='0.0' max='1.0' bdresolution='1' automationEnabled='false' value='1.0'>
      <line name='' version='2' max='1.0' min='0.0' bdresolution='1' color='-8355712' rightBound='false' endPointsLinked='false'>
        <linePoint x='0.0' y='1.0'/>
      </line>
    </parameter>
  </parameterList>
</effect>