#
# Create hidden work directories
#

[ "$1" == "" ] && exit 1

export TEMPLATES=$1
mkdir -p $TEMPLATES

#
# Create templates
#
# NB: This script is included as an example only - it should be rewritten and customised 
# for specific fx, data and track handling.
#

# Wipe existing ones since we'll recreate all here

rm -f $TEMPLATES/*.westley

# General stuff
# + nle_fixed fixes the initial size of an empty multitrack in frames
# + nle_zoom initialises the zoom level
# + nle_lock_tracks indicates the audio locking when moving items on the multitrack
# + nle_transitions indicates whether auto transitions are on or off
# + nle_position is the position of the cursor on the multitrack when loaded 
# HINT: Best leave these alone :-)

TEMPLATE_PROPS="nle_fixed=7500 nle_zoom=1 nle_lock_tracks=0 nle_transitions=0 nle_position=0"

# Tracks are defined by a label and a type
# + nle_label defines the label
# + nle_type defines the types of items that can be dropped on a particular track
#   this is a bit pattern made from the following values:
#   STORIES = 1		All video clips are categorised as stories
#   AUDIO = 2		All inputs that have audio are categorised as audio (ie: a clip is both story and audio)
#   STILLS = 4		Inputs that have no audio are categorised as stills
#   TEXT = 8		Used to indicate the track holds supers
#   VOICE = 16		Special categorisation that indicates audio only (an audio only clip is both audio and voice)
#   PROJECTS = 32	Categorisation of an injected nle project
# HINT: Changing TRACK2 from supers may cause undesirable or buggy behaviour

TRACK1_PROPS="nle_label=Visual nle_type=37"
TRACK2_PROPS="nle_label=Super nle_type=8"
TRACK3_PROPS="nle_label=Voice_Over nle_type=18"
TRACK4_PROPS="nle_label=Music nle_type=2"

# Attributes are treated as simple triggers of filters with optional data collection
# The filters themselves are defined in the mlt/src/modules/feeds/ directory
# Currently, the attributes are limited to collecting a single item of data and that is
# passed to the data_show attribute with a name of 'markup' (shotcut-nle limitation)
# Note that 'markup' can be used to populate any property you wish (usage defined in feeds properties)
# Also note that the display font and size (below) is also passed to the attributes
# When the attribute is prefixed with an * no data is collected for that item
# You can add your own feed filters as required (but note the limitations on the data collection)
# Attributes supported are limited to 15 (current UI imposed restriction)

VISUAL_SHOW="-filter data_show:%etv.properties track=-1"
VISUAL_ATTRIBS="nle_attributes=\"location,courtesy,*exclusive,*file_shot,*special\""

# The following define various font parameters for ETV
# Note that you must define fonts to use in two ways:
# + display font is the font used by mlt and pango (fc-list style)
# + capture font is the font used by shotcut and fltk (xlsfonts style)

FONT_BANGLA="nle_font_display=Gjmeshree0750 nle_font_capture=Gjmeshree0750 nle_font_attr_size=32 nle_font_super_size=48"
FONT_GUJARATI="nle_font_display=GJ-TTAvantika nle_font_capture=\"-altsys-gj_ttavantika-medium-r-normal--0-0-0-0-p-0-iso8859-1\" nle_font_attr_size=32 nle_font_super_size=48"
FONT_HINDI="nle_font_display=DV-TTYogesh nle_font_capture=\"-altsys-dv_ttyogesh-medium-r-normal--0-0-0-0-p-0-iso8859-1\" nle_font_attr_size=32 nle_font_super_size=48"
FONT_KANADA="nle_font_display=KN1-TTUma nle_font_capture=\"-misc-knbwlttuma-medium-r-normal--0-0-0-0-p-0-iso8859-1\" nle_font_attr_size=32 nle_font_super_size=48"
FONT_MARATHI="nle_font_display=DV-TTYogesh nle_font_capture=\"-altsys-dv_ttyogesh-medium-r-normal--0-0-0-0-p-0-iso8859-1\" nle_font_attr_size=32 nle_font_super_size=48"
FONT_ORIYA="nle_font_display=OR-TTMukta nle_font_capture=\"-altsys-or_ttmukta-medium-r-normal--0-0-0-0-p-0-iso8859-1\" nle_font_attr_size=32 nle_font_super_size=48"
FONT_TELUGU="nle_font_display=TL-TTHemalatha nle_font_capture=\"-altsys-tl_tthemalatha-medium-r-normal--0-0-0-0-p-0-iso8859-1\" nle_font_attr_size=32 nle_font_super_size=48"

# The package template

inigo nle_template="Package" $TEMPLATE_PROPS \
-track $TRACK1_PROPS $VISUAL_ATTRIBS nle_transition="luma" nle_transition_length=12 \
-blank 0 \
-null-track $TRACK2_PROPS \
-audio-track $TRACK3_PROPS \
-audio-track $TRACK4_PROPS \
-transition mix:0.8 always_active=1 length=12 a_track=0 b_track=2 \
-transition mix:0.5 always_active=1 length=12 a_track=0 b_track=3 \
-filter volume track=-1 normalise=-20db \
$VISUAL_SHOW \
-consumer westley:$TEMPLATES/Package.westley store="nle_"

for i in BANGLA GUJARATI HINDI KANADA MARATHI ORIYA TELUGU 
do

font=FONT_$i

inigo nle_template="Package - $i" $TEMPLATE_PROPS ${!font} \
-track $TRACK1_PROPS $VISUAL_ATTRIBS nle_transition="luma" nle_transition_length=12 \
-blank 0 \
-filter data_show:%etv.properties \
-null-track $TRACK2_PROPS \
-audio-track $TRACK3_PROPS \
-audio-track $TRACK4_PROPS \
-transition mix:0.8 always_active=1 a_track=0 b_track=2 \
-transition mix:0.5 always_active=1 a_track=2 b_track=3 \
-filter volume track=-1 normalise=-20db \
$VISUAL_SHOW \
-consumer westley:$TEMPLATES/Package-$i.westley store="nle_"

done

# The match package template

TRACK3_PROPS="nle_label=Voice_Over nle_type=7"

inigo nle_template="Match Package" $TEMPLATE_PROPS \
-track $TRACK1_PROPS $VISUAL_ATTRIBS nle_transition="luma" nle_transition_length=12 \
-blank 0 \
-null-track $TRACK2_PROPS \
-audio-track $TRACK3_PROPS \
-audio-track $TRACK4_PROPS \
-transition mix:0.8 always_active=1 length=12 a_track=0 b_track=2 \
-transition mix:0.5 always_active=1 length=12 a_track=0 b_track=3 \
-filter volume track=-1 normalise=-20db \
$VISUAL_SHOW \
-consumer westley:$TEMPLATES/Match-Package.westley store="nle_"

#
# PTC Demo - allows video and audio to be dropped on the 3rd track
#
# Note the modifications to the Package template on track 3:
#
# * it has a different nle_type property (to accept video and audio)
# * it is defined as a normal track (thus allowing it to overrun visual)
# * there is an additional composite transition which defines the effect 
#   (composite is the only supported transition for this but lumas are available)
#

TRACK3_PROPS="nle_label=Overlay nle_type=7"

inigo nle_template="PTC - Demo" $TEMPLATE_PROPS \
-track $TRACK1_PROPS $VISUAL_ATTRIBS nle_transition="luma" nle_transition_length=12 \
-blank 0 \
-null-track $TRACK2_PROPS \
-track $TRACK3_PROPS \
-audio-track $TRACK4_PROPS \
-transition composite always_active=1 no_alpha=1 geometry="100%,0:100%x100%;25=0%;-25=;-1=-100%" valign=c halign=c a_track=0 b_track=2 \
-transition mix:0.2 always_active=1 length=12 a_track=0 b_track=2 \
-transition mix:0.5 always_active=1 length=12 a_track=0 b_track=3 \
-filter volume track=-1 normalise=-20db \
$VISUAL_SHOW \
-consumer westley:$TEMPLATES/PTC-Demo.westley store="nle_"

TRACK3_PROPS="nle_label=Overlay_1 nle_type=7"
TRACK4_PROPS="nle_label=Overlay_2 nle_type=7"
TRACK5_PROPS="nle_label=Music nle_type=2"

inigo nle_template="Alpha - Demo" $TEMPLATE_PROPS \
-track $TRACK1_PROPS $VISUAL_ATTRIBS nle_transition="luma" nle_transition_length=12 \
-blank 0 \
-null-track $TRACK2_PROPS \
-track $TRACK3_PROPS \
-track $TRACK4_PROPS \
-audio-track $TRACK5_PROPS \
-transition composite full_alpha=1 always_active=1 geometry="0,0:100%x100%" distort=1 a_track=0 b_track=2 \
-transition composite full_alpha=1 always_active=1 geometry="0,0:100%x100%" distort=0 halign=c valign=c a_track=0 b_track=3 \
-transition mix:0.2 always_active=1 length=12 a_track=0 b_track=2 \
-transition mix:0.2 always_active=1 length=12 a_track=0 b_track=3 \
-transition mix:0.5 always_active=1 length=12 a_track=0 b_track=4 \
$VISUAL_SHOW \
-consumer westley:$TEMPLATES/AlphaDemo.westley store="nle_"

#
# Experimental
#
# This is a more complex example of a template...
#
# Note that no auto transitions are used - this a requirement of the
# 'non-standard' usage of attributes on the first track
#

TRACK1_PROPS="nle_label=Visual nle_type=37"
TRACK2_PROPS="nle_label=Super nle_type=8"
TRACK3_PROPS="nle_label=PIP_Right nle_type=7"
TRACK4_PROPS="nle_label=PIP_Left nle_type=7"
TRACK5_PROPS="nle_label=Alpha_1 nle_type=7"
TRACK6_PROPS="nle_label=Alpha_2 nle_type=7"
TRACK7_PROPS="nle_label=Music nle_type=2"

VISUAL_SHOW="-filter data_show:%etv.properties track=-1"
VISUAL_ATTRIBS="nle_attributes=\"location,courtesy,*exclusive,*file_shot,*special,*@border_left,*@border_right,*@greyscale,*@sepia,*@invert,*@charcoal\""

inigo nle_template="6 Tracks" $TEMPLATE_PROPS \
-track $TRACK1_PROPS $VISUAL_ATTRIBS \
-blank 0 \
-null-track $TRACK2_PROPS \
-track nle_attributes="*@greyscale,*@sepia,*@invert,*@charcoal" $TRACK3_PROPS \
-track nle_attributes="*@greyscale,*@sepia,*@invert,*@charcoal" $TRACK4_PROPS \
-track $TRACK5_PROPS \
-track $TRACK6_PROPS \
-track $TRACK7_PROPS \
-filter data_show:%example.properties track=0 \
-filter data_show:%border.properties track=0 \
-filter data_show:%example.properties track=2 \
-transition composite always_active=1 no_alpha=1 geometry="100%,17.5%:45%x45%;25=52.5%" valign=c halign=c cycle=0.5 a_track=0 b_track=2 \
-transition composite always_active=1 geometry="-100%,17.5%:45%x45%;25=2.5%" valign=c halign=c cycle=0.5 a_track=0 b_track=3 \
-transition composite always_active=1 geometry="0,0:100%x100%" distort=1 a_track=0 b_track=4 \
-transition composite always_active=1 geometry="0,0:100%x100%" distort=0 valign=c halign=c a_track=0 b_track=5 \
-transition mix:0.5 always_active=1 length=12 a_track=0 b_track=2 \
-transition mix:0.5 always_active=1 length=12 a_track=0 b_track=3 \
-transition mix:0.5 always_active=1 length=12 a_track=0 b_track=6 \
$VISUAL_SHOW \
-consumer westley:$TEMPLATES/6Tracks.westley store="nle_"

#
# BASIC TEMPLATES FROM DOCS
#

inigo nle_template="Single Track" nle_prefix="STR_" \
-track nle_label=Visual nle_type=1 -blank 0 \
-consumer westley:$TEMPLATES/SingleTrack.westley store="nle_"

inigo nle_template="Audio Mixing" \
-track nle_label=Visual nle_type=1 -blank 0 \
-track nle_label=Audio nle_type=2 \
-transition mix:0.5 always_active=1 length=25 a_track=0 b_track=1 \
-consumer westley:$TEMPLATES/AudioMixing.westley store="nle_"

inigo nle_template="Auto Transitions" \
-track nle_label=Visual nle_type=1 nle_transition=luma nle_transition_length=12 -blank 0 \
-track nle_label=Audio nle_type=2 \
-transition mix:0.5 always_active=1 length=25 a_track=0 b_track=1 \
-consumer westley:$TEMPLATES/AutoTransitions.westley store="nle_"

inigo nle_template="Supers" \
-track nle_label=Visual nle_type=1 nle_transition=luma nle_transition_length=12 -blank 0 \
-null-track nle_label="Super" nle_type=8 \
-track nle_label=Audio nle_type=2 \
-transition mix:0.5 always_active=1 length=25 a_track=0 b_track=2 \
-filter data_show:%etv.properties track=-1 \
-consumer westley:$TEMPLATES/Supers.westley store="nle_"

inigo nle_template="Attributes" \
-track nle_label=Visual nle_type=1 nle_transition=luma nle_transition_length=12 \
nle_attributes="location,courtesy,*exclusive,*file_shot,*special" \
-blank 0 \
-null-track nle_label="Super" nle_type=8 \
-track nle_label=Audio nle_type=2 \
-transition mix:0.5 always_active=1 length=25 a_track=0 b_track=2 \
-filter data_show:%etv.properties track=-1 \
-consumer westley:$TEMPLATES/Attributes.westley store="nle_"

