| 2122 | } |
| 2123 | |
| 2124 | void 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); |
nothing calls this directly
no test coverage detected