-- $NWCUT$CONFIG: FileText $ nwcut.setlevel(2) nwcut.status = nwcut.const.rc_Succes --nwcut.status = nwcut.const.rc_Report local progname = 'Sibling' local ASI = 0 -- Active Staff Parameters local ASN = "UnDefined"; local CSI = 0 -- Current Staff Parameters local CSN = "UnDefined"; local DSG = "SIBLINGS" local DSPN = "SiblingInstrument" local HelpMsg = [[ This tool mutes the active staff and adds 2 copies all its relevant information into 2 new sibling staves. The active staff is slightly modified if it is not already in this state: the instrument is explicitely specified [line 33] and the staff is muted [line 34]. If staves with sibling name _Sibling1 or _Sibling1 already exist, they will be removed [line 36]. 2 (hidden) sibling staves are added at the end of the score based on the ActiveStaff (named : _sibling) [line 67 and line 68]. The midi channels used for sibling staves are 15 and 16 [line 48] and since they are at the end of the score, they will override midi definitions for staves that were assigned earlier to these channels. The sibling staves are made invisible to avoid sibling them again [line 52]. The sibling staves receive Instrument Patches 00 (piano) and 89 (Pad 2 warm) [line 56]. Instrument changes in the ActiveStaff are skipped in the sibling [line 58]. ]] -------------------------------------- -- Main processing ------------------- -------------------------------------- assert(nwcut.getprop('Mode') == nwcut.const.mode_FileText, "Input type must be 'File Text'") assert(nwcut.getprop('ReturnMode') == nwcut.const.mode_FileText, "Under 'Options', check 'Returns File Text'") mt = {} ; mt[0]={} for item in nwcut.items() do if item:Is('Editor') then ASI = item.Opts.ActiveStaff + 0 ; end--if if item:Is('AddStaff') then CSI = CSI + 1 ; mt[CSI] = {} ; CSN = item.Opts.Name.Text ; CSOGN = item.Opts.Group.Text ; if CSI == ASI then ASN = CSN end ; end--if if item:Is('StaffInstrument') then if not item.Opts.Patch then item.Opts.Patch=0 end ; if not item.Opts.Name then item.Opts.Name="\"NN\"" end ; end--if if item:Is('StaffProperties') and ( CSI == ASI ) and ( item.Opts.Muted ) then item.Opts.Muted="Y" end--if if not ( string.gsub(CSN,'%-','_') == string.gsub(ASN,'%-','_').."_sibling1" or string.gsub(CSN,'%-','_') == string.gsub(ASN,'%-','_').."_sibling2" ) then table.insert(mt[CSI],tostring(item)) end--if if CSI == ASI then SS1 = nwcItem.new(tostring(item)) ; SS2 = nwcItem.new(tostring(item)) if item:Is('AddStaff') then SS1.Opts.Name = CSN .. "_sibling1" ; SS2.Opts.Name = CSN .. "_sibling2" ; SS1.Opts.Group = DSG ; SS2.Opts.Group = DSG ST1 = {} ; ST2 = {} ; end--if if item:Is('StaffProperties') then if ( item.Opts.Muted or item.Opts.Channel or item.Opts.Volume or item.Opts.StereoPan) then SS1.Opts.Muted = "N" ; SS2.Opts.Muted = "N" SS1.Opts.Channel = 15 ; SS2.Opts.Channel = 16 SS1.Opts.Volume = 100 ; SS2.Opts.Volume = 100 SS1.Opts.StereoPan = 64 ; SS2.Opts.StereoPan = 64 elseif item.Opts.Visible then SS1.Opts.Visible = "N" ; SS2.Opts.Visible = "N" end--if end--if if item:Is('StaffInstrument') then SS1.Opts.Patch = 89 ; SS2.Opts.Patch = 0 ; SS1.Opts.Name = DSPN ; SS2.Opts.Name = DSPN end--if if item:Is('TempoVariance') and item.Opts.Pause then SS1.Opts.Pause = 0 ; SS2.Opts.Pause = 0 ; end--if if not item:Is('Instrument') then table.insert(ST1,tostring(SS1)) ; table.insert(ST2,tostring(SS2)) ; end--if end--if end--for for j=0,CSI do for i=1,#mt[j] do nwcut.writeline (mt[j][i]) end--for end--for for i=1,#ST1 do nwcut.writeline (ST1[i]) end--for for i=1,#ST2 do nwcut.writeline (ST2[i]) end--for