MCPcopy Create free account
hub / github.com/BespokeSynth/BespokeSynth / PostRepatch

Method PostRepatch

Source/MidiController.cpp:2124–2190  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2122}
2123
2124void MidiController::PostRepatch(PatchCableSource* cableSource, bool fromUserClick)
2125{
2126 for (auto* grid : mGrids)
2127 {
2128 if (cableSource == grid->mGridCable)
2129 {
2130 grid->mGridControlTarget[mControllerPage] = dynamic_cast<GridControlTarget*>(cableSource->GetTarget());
2131 if (grid->mGridControlTarget[mControllerPage])
2132 {
2133 GridControllerMidi* gridController = new GridControllerMidi();
2134 grid->mGridControlTarget[mControllerPage]->SetGridController(gridController);
2135 gridController->SetUp(grid, mControllerPage, this);
2136 }
2137 return;
2138 }
2139 }
2140
2141 bool repatched = false;
2142 for (auto* connection : mConnections)
2143 {
2144 repatched = connection->PostRepatch(cableSource, fromUserClick);
2145 if (repatched)
2146 break;
2147 }
2148
2149 if (cableSource->GetTarget()) //need to make connection
2150 {
2151 if (fromUserClick && !repatched)
2152 {
2153 int layoutControl = GetLayoutControlIndexForCable(cableSource);
2154 if (layoutControl != -1)
2155 {
2156 UIControlConnection* connection = AddControlConnection(mLayoutControls[layoutControl].mType, mLayoutControls[layoutControl].mControl, -1, dynamic_cast<IUIControl*>(cableSource->GetTarget()));
2157
2158 RadioButton* radioButton = dynamic_cast<RadioButton*>(cableSource->GetTarget());
2159 if (radioButton && mLayoutControls[layoutControl].mDrawType == kDrawType_Button)
2160 {
2161 connection->mType = kControlType_SetValue;
2162 float closestSq = FLT_MAX;
2163 int closestIdx = 0;
2164 ofVec2f mousePos(TheSynth->GetRawMouseX(), TheSynth->GetRawMouseY());
2165 for (int i = 0; i < radioButton->GetNumValues(); ++i)
2166 {
2167 float distSq = (mousePos - radioButton->GetOptionPosition(i)).distanceSquared();
2168 if (distSq < closestSq)
2169 {
2170 closestSq = distSq;
2171 closestIdx = i;
2172 }
2173 }
2174 connection->mValue = closestIdx;
2175 }
2176 }
2177 }
2178 }
2179 else // need to remove a connection if no cables remain
2180 {
2181 auto uiConnection = GetConnectionForCableSource(cableSource);

Callers

nothing calls this directly

Calls 9

SetGridControllerMethod · 0.80
GetRawMouseXMethod · 0.80
GetRawMouseYMethod · 0.80
distanceSquaredMethod · 0.80
GetOptionPositionMethod · 0.80
GetPageMethod · 0.80
GetTargetMethod · 0.45
SetUpMethod · 0.45
GetNumValuesMethod · 0.45

Tested by

no test coverage detected