
#include "Matrix44Cvm.hpp"
#include "mixer.hpp"

void Matrix44Cvm::processAlways(const ProcessArgs& args) {
	int position = 0;
	int baseID = 0;
	if (baseConnected()) {
		Matrix44ExpanderMessage* bm = fromBase();
		baseID = bm->baseID;
		position = bm->position;
	}
	setBaseIDAndPosition(baseID, position);

	if (expanderConnected()) {
		Matrix44ExpanderMessage* te = toExpander();
		te->baseID = _baseID;
		te->position = _position > 0 ? _position + 1 : 0;
	}
}

struct Matrix44CvmWidget : MutesMatrixExpanderModuleWidget {
	static constexpr int hp = 10;

	Matrix44CvmWidget(Matrix44Cvm* module) {
		setModule(module);
		box.size = Vec(RACK_GRID_WIDTH * hp, RACK_GRID_HEIGHT);
		setPanel(box.size, "Matrix44Cvm");
		createScrews();

		// generated by svg_widgets.rb
		auto mute11ParamPosition = Vec(16.75, 61.75);
		auto mute21ParamPosition = Vec(16.75, 94.25);
		auto mute31ParamPosition = Vec(16.75, 126.75);
		auto mute41ParamPosition = Vec(16.75, 159.25);
		auto mute12ParamPosition = Vec(49.25, 61.75);
		auto mute22ParamPosition = Vec(49.25, 94.25);
		auto mute32ParamPosition = Vec(49.25, 126.75);
		auto mute42ParamPosition = Vec(49.25, 159.25);
		auto mute13ParamPosition = Vec(81.75, 61.75);
		auto mute23ParamPosition = Vec(81.75, 94.25);
		auto mute33ParamPosition = Vec(81.75, 126.75);
		auto mute43ParamPosition = Vec(81.75, 159.25);
		auto mute14ParamPosition = Vec(114.25, 61.75);
		auto mute24ParamPosition = Vec(114.25, 94.25);
		auto mute34ParamPosition = Vec(114.25, 126.75);
		auto mute44ParamPosition = Vec(114.25, 159.25);

		auto cv11InputPosition = Vec(14.25, 217.25);
		auto cv21InputPosition = Vec(14.25, 249.75);
		auto cv31InputPosition = Vec(14.25, 282.25);
		auto cv41InputPosition = Vec(14.25, 314.75);
		auto cv12InputPosition = Vec(46.75, 217.25);
		auto cv22InputPosition = Vec(46.75, 249.75);
		auto cv32InputPosition = Vec(46.75, 282.25);
		auto cv42InputPosition = Vec(46.75, 314.75);
		auto cv13InputPosition = Vec(79.25, 217.25);
		auto cv23InputPosition = Vec(79.25, 249.75);
		auto cv33InputPosition = Vec(79.25, 282.25);
		auto cv43InputPosition = Vec(79.25, 314.75);
		auto cv14InputPosition = Vec(111.75, 217.25);
		auto cv24InputPosition = Vec(111.75, 249.75);
		auto cv34InputPosition = Vec(111.75, 282.25);
		auto cv44InputPosition = Vec(111.75, 314.75);
		// end generated by svg_widgets.rb

		addParam(createParam<SoloMuteButton>(mute11ParamPosition, module, Matrix44Cvm::MUTE11_PARAM));
		addParam(createParam<SoloMuteButton>(mute21ParamPosition, module, Matrix44Cvm::MUTE21_PARAM));
		addParam(createParam<SoloMuteButton>(mute31ParamPosition, module, Matrix44Cvm::MUTE31_PARAM));
		addParam(createParam<SoloMuteButton>(mute41ParamPosition, module, Matrix44Cvm::MUTE41_PARAM));
		addParam(createParam<SoloMuteButton>(mute12ParamPosition, module, Matrix44Cvm::MUTE12_PARAM));
		addParam(createParam<SoloMuteButton>(mute22ParamPosition, module, Matrix44Cvm::MUTE22_PARAM));
		addParam(createParam<SoloMuteButton>(mute32ParamPosition, module, Matrix44Cvm::MUTE32_PARAM));
		addParam(createParam<SoloMuteButton>(mute42ParamPosition, module, Matrix44Cvm::MUTE42_PARAM));
		addParam(createParam<SoloMuteButton>(mute13ParamPosition, module, Matrix44Cvm::MUTE13_PARAM));
		addParam(createParam<SoloMuteButton>(mute23ParamPosition, module, Matrix44Cvm::MUTE23_PARAM));
		addParam(createParam<SoloMuteButton>(mute33ParamPosition, module, Matrix44Cvm::MUTE33_PARAM));
		addParam(createParam<SoloMuteButton>(mute43ParamPosition, module, Matrix44Cvm::MUTE43_PARAM));
		addParam(createParam<SoloMuteButton>(mute14ParamPosition, module, Matrix44Cvm::MUTE14_PARAM));
		addParam(createParam<SoloMuteButton>(mute24ParamPosition, module, Matrix44Cvm::MUTE24_PARAM));
		addParam(createParam<SoloMuteButton>(mute34ParamPosition, module, Matrix44Cvm::MUTE34_PARAM));
		addParam(createParam<SoloMuteButton>(mute44ParamPosition, module, Matrix44Cvm::MUTE44_PARAM));

		addInput(createInput<Port24>(cv11InputPosition, module, Matrix44Cvm::CV11_INPUT));
		addInput(createInput<Port24>(cv21InputPosition, module, Matrix44Cvm::CV21_INPUT));
		addInput(createInput<Port24>(cv31InputPosition, module, Matrix44Cvm::CV31_INPUT));
		addInput(createInput<Port24>(cv41InputPosition, module, Matrix44Cvm::CV41_INPUT));
		addInput(createInput<Port24>(cv12InputPosition, module, Matrix44Cvm::CV12_INPUT));
		addInput(createInput<Port24>(cv22InputPosition, module, Matrix44Cvm::CV22_INPUT));
		addInput(createInput<Port24>(cv32InputPosition, module, Matrix44Cvm::CV32_INPUT));
		addInput(createInput<Port24>(cv42InputPosition, module, Matrix44Cvm::CV42_INPUT));
		addInput(createInput<Port24>(cv13InputPosition, module, Matrix44Cvm::CV13_INPUT));
		addInput(createInput<Port24>(cv23InputPosition, module, Matrix44Cvm::CV23_INPUT));
		addInput(createInput<Port24>(cv33InputPosition, module, Matrix44Cvm::CV33_INPUT));
		addInput(createInput<Port24>(cv43InputPosition, module, Matrix44Cvm::CV43_INPUT));
		addInput(createInput<Port24>(cv14InputPosition, module, Matrix44Cvm::CV14_INPUT));
		addInput(createInput<Port24>(cv24InputPosition, module, Matrix44Cvm::CV24_INPUT));
		addInput(createInput<Port24>(cv34InputPosition, module, Matrix44Cvm::CV34_INPUT));
		addInput(createInput<Port24>(cv44InputPosition, module, Matrix44Cvm::CV44_INPUT));
	}
};

Model* modelMatrix44Cvm = createModel<Matrix44Cvm, Matrix44CvmWidget>("Bogaudio-Matrix44Cvm", "MX44CVM", "CV and mutes expander for MATRIX44", "Mixer", "Expander", "Polyphonic");
