// Helper function for generating stripes section
function generateStripesSection(labels = true, i = 27, s = 15)
{
	return {
		nsClass: "GXDrawView",
		gxLayout: [`V:|-${i}-[s1]-${s}-[s2]-${s}-[s3]-${s}-[s4]-${s}-[s5]-${s}-[s6]-${s}-[s7]-${s}-[s8]-${s}-[s9]-${i}-|`],
		gxChildViews: [
			{ gxViewName: "s1", "+": labels ? "EqStripe" : "EqStripe.noLabel", gxLabelText: " 12dB" },
			{ gxViewName: "s2", "+": labels ? "EqStripe" : "EqStripe.noLabel", gxLabelText: "" },
			{ gxViewName: "s3", "+": labels ? "EqStripe" : "EqStripe.noLabel", gxLabelText: " 6dB" },
			{ gxViewName: "s4", "+": labels ? "EqStripe" : "EqStripe.noLabel", gxLabelText: "" },
			{ gxViewName: "s5", "+": labels ? "EqStripe" : "EqStripe.noLabel", gxLabelText: " 0dB" },
			{ gxViewName: "s6", "+": labels ? "EqStripe" : "EqStripe.noLabel", gxLabelText: "" },
			{ gxViewName: "s7", "+": labels ? "EqStripe" : "EqStripe.noLabel", gxLabelText: "-6dB" },
			{ gxViewName: "s8", "+": labels ? "EqStripe" : "EqStripe.noLabel", gxLabelText: "" },
			{ gxViewName: "s9", "+": labels ? "EqStripe" : "EqStripe.noLabel", gxLabelText: "-12dB" },
		],
	};
}

// Helper function for creating a slider
function createSlider(name, frequency, axFrequency, valueKey, axTitle) {
	return {
		nsClass: "GXDrawView",
		gxViewName: name,
		gxLayout: [
			"H:[self(>=label,>=33)]",
			"V:|-0-[self]-0-|",
			"V:|-0-[label(14)]-5-[slider]-5-[readout(14)]-0-|&alignCenterX",
			"H:[slider(18)]",
			"H:|[label]|",
		],
		gxChildViews: {
			slider: {
				"+": "SliderView.trackUnfilled.vertical",
				gxValueKey: valueKey,
				gxVertical: true,
				gxDetentPainter: fillPainterWithSize("BackColor2", "4, 0.4"),
				gxDefaultValue: 0.5,
				gxDetents: "0.5",
				axFormatter: {
					nsClass: "GXScaledFormatter",
					offset: -0.5,
					scale: 24,
					format: "%+ .1f dB",
					zeroFormat: "0dB",
				},
				gxKeystrokeStepSize: 1.0 / 24.0,
				axTitle: axTitle,
			},
			label: labelView(frequency, "foreColor1.size10"),
			readout: {
				"+": "LabelView.centerx.colorTheme1.size11",
				gxValueKey: valueKey,
				gxFormatter: {
					nsClass: "GXScaledFormatter",
					offset: -0.5,
					scale: 24,
					format: "%.1f",
					zeroFormat: "0" },
				gxIntrinsicWidth: 38,
				gxClickValue: 0.5,
				gxDisableOnKey: "nodeModel.bypassed",
			},
		},
	};
}

// Updated markup with preamp and eq sliders in distinct sections
markup.push({
	Equalizer10View: {
		"+": "GroupView",
		gxCanMoveWindow: false,
		gxDragger : "SliderSelectionDragger",
		gxLayout: [
			"V:|[preampSection]|",
			"V:[eqSection(==preampSection)]",
			"H:|-(-3)-[preampSection(40)]-4-[eqSection]-0-|&alignCenterY"
		],
		gxChildViews: {
			// preamp section
			preampSection: {
				nsClass: "GXDrawView",
				gxLayout: [
					"V:|-2-[preampStripes]-2-|",
					"V:|-0-[preamp]-0-|",
					"H:|-22-[preampStripes]-0-|",
					"H:|[preamp]|",
				],
				gxChildViews: {
					preamp: createSlider("preamp", "Preamp", "Preamp", "nodeModel.preamp", "Preamp"),
					preampStripes: generateStripesSection(false),
				},
			},
			// eq section
			eqSection: {
				nsClass: "GXDrawView",
				gxLayout: [
					"V:|-2-[eqStripes]-2-|",
					"V:|-0-[eqSliders]-0-|",
					"H:|-0-[eqStripes]-18-|",
					"H:|-36-[eqSliders]-0-|",
				],
				gxChildViews: {
					eqSliders: {
						nsClass: "GXDrawView",
						gxLayout: [
							"H:|-0-[b0]-9-[b1]-9-[b2]-9-[b3]-9-[b4]-9-[b5]-9-[b6]-9-[b7]-9-[b8]-9-[b9]-0-|"
						],
						gxChildViews: [
							createSlider("b0", "32Hz", "32", "nodeModel.band0", "32 hertz band"),
							createSlider("b1", "64Hz", "64", "nodeModel.band1", "64 hertz band"),
							createSlider("b2", "125Hz", "125", "nodeModel.band2", "125 hertz band"),
							createSlider("b3", "250Hz", "250", "nodeModel.band3", "250 hertz band"),
							createSlider("b4", "500Hz", "500", "nodeModel.band4", "500 hertz band"),
							createSlider("b5", "1kHz", "1kilo", "nodeModel.band5", "1k hertz band"),
							createSlider("b6", "2kHz", "2kilo", "nodeModel.band6", "2k hertz band"),
							createSlider("b7", "4kHz", "4kilo", "nodeModel.band7", "4k hertz band"),
							createSlider("b8", "8kHz", "8kilo", "nodeModel.band8", "8k hertz band"),
							createSlider("b9", "16kHz", "16kilo", "nodeModel.band9", "16k hertz band"),
						],
					},
					eqStripes: generateStripesSection(),
				},
			},
		},
	},

	Equalizer10Popover: {
		"+": "PopoverTemplate",
		gxTitle: "10-Band Equalizer",
		axTitle: "Ten Band Equalizer",
		gxLayout: [
			"H:|-12-[self]-12-|",
			"V:|-12-[self]-12-|",
			"V:|-41-[settingsContainer]-8-[presetsGroup]",
			"H:|-0-[settingsContainer]-0-|",
		],
		gxCanDrawSubviewsIntoLayer: true,
		gxWantsLayer: true,
		gxChildViews: {
			title: "PopoverTitle",
			switch: "PopoverOnOffSwitch",
			presetsGroup: presetsGroup(),
			settingsContainer: {
				nsClass: "GXDrawView"
			},
		},
	},

	EqStripe: {
		nsClass: "GXDrawView",
		gxBackPainter: fillPainter("BackColor3.alphaBg20"),
		gxLayout: [
			"H:|-0-[selfLabel(30)]-6-[self]-0-|&alignCenterY",
			"V:[self(0.5)]"
		],
		gxLabelTemplate: {
			"+": "LabelView.center.top.darker.size9",
			gxIntrinsicHeight: 14,
		},
		"noLabel" :
		{
			gxLayout: [
				"H:|-0-[self]-0-|&alignCenterY",
				"V:[self(0.5)]"
			],
			gxLabelTemplate : "",
		}
	},
	
// MARK: - Sparkline inline icon painter

PresetSparkCell:
{
	nsClass: "GXTextAttachmentCell",
	gxBaselineOffset: -4,
	gxForePainter: { "+": "PresetSparkPainter" },
	gxDefaultValue: "UFU1P0pEND8dIio/MzMLP+nuFj+wqhI/UFUlP6IGvz5NRnM+6e4WPw==",
},

PresetSparkPainter:
{
	nsClass: "GXSparklinePainter",
	gxStrokeColor: "ForeColor1",
	gxDefaultSize: "26, 16",
	gxEdgeInsets: "1, 0, 3, 0",	// leave space for points, plus more space on right
	gxStrokeWidth: 1.5,
},


// MARK: - EQ presets

Equalizer10Presets:
{
	gxDefaultPresets: [
		{ presetName: "Off (Flat)",     presetValues: {  "band0":0.500000, "band1":0.500000, "band2":0.500000, "band3":0.500000, "band4":0.500000, "band5":0.500000, "band6":0.500000, "band7":0.500000, "band8":0.500000, "band9":0.500000  }},
		{ presetName: "Acoustic",       presetValues: {  "band0":0.708333, "band1":0.704167, "band2":0.664583, "band3":0.543750, "band4":0.589583, "band5":0.572917, "band6":0.645833, "band7":0.670417, "band8":0.647917, "band9":0.589583  }},
		{ presetName: "AirPods",       	presetValues: {  "band0":0.582306, "band1":0.602387, "band2":0.559749, "band3":0.500000, "band4":0.500000, "band5":0.500000, "band6":0.549295, "band7":0.583027, "band8":0.624890, "band9":0.626541  }},
		{ presetName: "Bass Booster",   presetValues: {  "band0":0.729167, "band1":0.677083, "band2":0.645833, "band3":0.604167, "band4":0.552083, "band5":0.500000, "band6":0.500000, "band7":0.500000, "band8":0.500000, "band9":0.500000  }},
		{ presetName: "Bass Reducer",   presetValues: {  "band0":0.270833, "band1":0.322917, "band2":0.354167, "band3":0.395833, "band4":0.447917, "band5":0.500000, "band6":0.500000, "band7":0.500000, "band8":0.500000, "band9":0.500000  }},
		{ presetName: "Classical",      presetValues: {  "band0":0.697917, "band1":0.656250, "band2":0.625000, "band3":0.604167, "band4":0.437500, "band5":0.437500, "band6":0.500000, "band7":0.593750, "band8":0.635417, "band9":0.656250  }},
		{ presetName: "Dance",          presetValues: {  "band0":0.648750, "band1":0.772917, "band2":0.707917, "band3":0.500000, "band4":0.580000, "band5":0.652083, "band6":0.714583, "band7":0.689167, "band8":0.649583, "band9":0.500000  }},
		{ presetName: "Deep",           presetValues: {  "band0":0.706250, "band1":0.647917, "band2":0.572917, "band3":0.541667, "band4":0.618750, "band5":0.604167, "band6":0.560417, "band7":0.410417, "band8":0.352083, "band9":0.308333  }},
		{ presetName: "Electronic",     presetValues: {  "band0":0.677083, "band1":0.658333, "band2":0.550000, "band3":0.500000, "band4":0.410417, "band5":0.593750, "band6":0.535417, "band7":0.552083, "band8":0.664583, "band9":0.700000  }},
		{ presetName: "Hip-Hop",        presetValues: {  "band0":0.708333, "band1":0.677083, "band2":0.562500, "band3":0.625000, "band4":0.458333, "band5":0.458333, "band6":0.562500, "band7":0.479167, "band8":0.583333, "band9":0.625000  }},
		{ presetName: "Jazz",           presetValues: {  "band0":0.666667, "band1":0.625000, "band2":0.562500, "band3":0.593750, "band4":0.437500, "band5":0.437500, "band6":0.500000, "band7":0.562500, "band8":0.625000, "band9":0.656250  }},
		{ presetName: "Latin",          presetValues: {  "band0":0.687500, "band1":0.625000, "band2":0.500000, "band3":0.500000, "band4":0.437500, "band5":0.437500, "band6":0.437500, "band7":0.500000, "band8":0.625000, "band9":0.687500  }},
		{ presetName: "Loudness",       presetValues: {  "band0":0.750000, "band1":0.666667, "band2":0.500000, "band3":0.500000, "band4":0.416667, "band5":0.500000, "band6":0.458333, "band7":0.291667, "band8":0.708333, "band9":0.541667  }},
		{ presetName: "Lounge",         presetValues: {  "band0":0.375000, "band1":0.437500, "band2":0.479167, "band3":0.562500, "band4":0.666667, "band5":0.604167, "band6":0.500000, "band7":0.437500, "band8":0.583333, "band9":0.541667  }},
		{ presetName: "Piano",          presetValues: {  "band0":0.625000, "band1":0.583333, "band2":0.500000, "band3":0.604167, "band4":0.625000, "band5":0.562500, "band6":0.645833, "band7":0.687500, "band8":0.625000, "band9":0.645833  }},
		{ presetName: "Pop",            presetValues: {  "band0":0.437500, "band1":0.458333, "band2":0.500000, "band3":0.583333, "band4":0.666667, "band5":0.666667, "band6":0.583333, "band7":0.500000, "band8":0.458333, "band9":0.437500  }},
		{ presetName: "R&B",            presetValues: {  "band0":0.609167, "band1":0.788333, "band2":0.735417, "band3":0.555417, "band4":0.408750, "band5":0.437500, "band6":0.596667, "band7":0.610417, "band8":0.625000, "band9":0.656250  }},
		{ presetName: "Rock",           presetValues: {  "band0":0.708333, "band1":0.666667, "band2":0.625000, "band3":0.562500, "band4":0.479167, "band5":0.458333, "band6":0.520833, "band7":0.604167, "band8":0.645833, "band9":0.687500  }},
		{ presetName: "Small Speakers", presetValues: {  "band0":0.729167, "band1":0.677083, "band2":0.645833, "band3":0.604167, "band4":0.552083, "band5":0.500000, "band6":0.447917, "band7":0.395833, "band8":0.354167, "band9":0.322917  }},
		{ presetName: "Spoken Word",    presetValues: {  "band0":0.355833, "band1":0.480417, "band2":0.500000, "band3":0.528750, "band4":0.644167, "band5":0.692083, "band6":0.701667, "band7":0.678333, "band8":0.605833, "band9":0.500000  }},
		{ presetName: "Treble Booster", presetValues: {  "band0":0.500000, "band1":0.500000, "band2":0.500000, "band3":0.500000, "band4":0.500000, "band5":0.552083, "band6":0.604167, "band7":0.645833, "band8":0.677083, "band9":0.729167  }},
		{ presetName: "Treble Reducer", presetValues: {  "band0":0.500000, "band1":0.500000, "band2":0.500000, "band3":0.500000, "band4":0.500000, "band5":0.447917, "band6":0.395833, "band7":0.354167, "band8":0.322917, "band9":0.270833  }},
		{ presetName: "Vocal Booster",  presetValues: {  "band0":0.437500, "band1":0.375000, "band2":0.375000, "band3":0.562500, "band4":0.656250, "band5":0.656250, "band6":0.625000, "band7":0.562500, "band8":0.500000, "band9":0.437500  }}
	],
},


})
