Main Page | Namespaces | Classes | Compounds | Files | Compound Members | Related MainDialog.cpp00001 // 00002 // SYNTOPIA. See http://Syntopia.sourceforge.net for details and documentation. 00003 // 00004 // Author of this file: Mikael Hvidtfeldt Christensen (mikaelc@users.sourceforge.net) 00005 // 00006 00007 #include "mainDialog.h" 00008 #include <vector> 00009 #include "Modules.h" 00010 #include <sstream> 00011 #include "FilterDialog.h" 00012 00013 namespace SynthGUI { 00014 00015 void 00016 mainDialog::drawMod(int x, int y, int x2, int y2, std::string s, mod * md, bool drawLines ) 00017 { 00018 // Draws a rectangle representing a module. 00019 00020 //ii++; 00021 //std::cout << ii << " "; 00022 00023 C1 = RGB(225,225,200); 00024 // A 'chosen' mod will be painted in a different color. 00025 if (myModList->chosen != -1) 00026 if (myModList->mods[myModList->chosen] == md) C1 = RGB(225,125,100); 00027 00028 // Bottom line 00029 int ins = md->mv[0]->getNoInputs(); 00030 int outs = md->mv[0]->getNoOutputs(); 00031 00032 00033 if (drawLines) { 00034 // Draw connector lines 00035 modCanvas->setColor(100,100,100); 00036 for (int i = 0; i< ins; i++) 00037 { 00038 if (md->mv[0]->getInput(i)->ConFrom != 0) 00039 { 00040 // get the module that input nr. i is connected to. 00041 // convert module to mod. 00042 int mds = myModList->getMod(md->mv[0]->getInput(i)->ConFrom->HostModule); 00043 if (mds != -1) { 00044 // the module connected to, is actually a mod (which means it is displayed) 00045 int mx = x+2; 00046 int my = y+30; 00047 int mx2 = myModList->mods[mds]->x2-2; 00048 int my2 = myModList->mods[mds]->y+30; 00049 modCanvas->line(mx,my,mx2,my2); 00050 00051 int mx3 = (mx2+mx)/2; // Calculate halfway point 00052 int my3 = (my2+my)/2; 00053 float l = sqrt((mx2-mx)*(mx2-mx)+(my2-my)*(my2-my)); 00054 00055 float mx4 = (mx2-mx)/l; // Unit vector 00056 float my4 = (my2-my)/l; 00057 00058 00059 if (l > 20.0) { 00060 // Only draw the arrow if there are plenty of space between the modules 00061 modCanvas->line(mx3+int (-my4*5),my3+int (mx4*5),mx3-int (mx4*8),my3-int (my4*8)); 00062 modCanvas->line(mx3+int (my4*5),my3+int (-mx4*5),mx3-int (mx4*8),my3-int (my4*8)); 00063 modCanvas->line(mx3+int (my4*5),my3+int (-mx4*5),mx3+int (-my4*5),my3+int (mx4*5)); 00064 } 00065 } 00066 } 00067 } 00068 00069 } else { 00070 // Main box 00071 modCanvas->setBrush(200,200,180); 00072 00073 if (md->mv[0]->hostVoice != 0) { 00074 // Part of polyphony voice. 00075 // Draw layered module. 00076 modCanvas->rectangle(x+4,y+4,x2+4,y2+4); 00077 modCanvas->rectangle(x+2,y+2,x2+2,y2+2); 00078 } 00079 00080 modCanvas->rectangle(x,y,x2,y2); 00081 00082 00083 // Upper and lower rects 00084 modCanvas->setBrush(C1); 00085 modCanvas->rectangle(x,y,x2,y+20); 00086 modCanvas->rectangle(x,y2-20,x2,y2); 00087 00088 // Title 00089 modCanvas->setTextColor(0,0,55); 00090 modCanvas->setBGColor(C1); 00091 modCanvas->print(x+2,y+2,s); 00092 00093 // Title 00094 modCanvas->setTextColor(0,55,00); 00095 modCanvas->setBGColor(C1); 00096 std::stringstream a; 00097 00098 00099 00100 // Those annoying type conversions 00101 a << "IN: "<< ins << " OUT: " << outs; 00102 std::string s2; 00103 s2= a.str(); 00104 00105 modCanvas->print(x+2,y2-18,s2); 00106 00107 00108 } 00109 00110 00111 } 00112 00113 void mainDialog::drawmain() { 00114 // Clear canvas 00115 modCanvas->clear(); 00116 /* 00117 int w = modCanvas->getWidth(); 00118 int h = modCanvas->getHeight(); 00119 for (int y = 0; y < h; y++) 00120 { 00121 int temp = (y*255)/h; 00122 modCanvas->setColor( 12, 12, 12); 00123 modCanvas->line(0,y,w,y); 00124 00125 }*/ 00126 00127 // Draw modules in two passes: 00128 for (int i=0; i<myModList->mods.size(); i++) { 00129 // First draw connector lines 00130 drawMod(myModList->mods[i]->x,myModList->mods[i]->y,myModList->mods[i]->x+100,myModList->mods[i]->y+80,myModList->mods[i]->mv[0]->getName(), myModList->mods[i], true); 00131 } 00132 00133 for (int j=0; j<myModList->mods.size(); j++) { 00134 // Second draw the module rectangles. 00135 drawMod(myModList->mods[j]->x,myModList->mods[j]->y,myModList->mods[j]->x+100,myModList->mods[j]->y+80,myModList->mods[j]->mv[0]->getName(), myModList->mods[j], false); 00136 } 00137 00138 // Update double buffer. 00139 modCanvas->doDraw(); 00140 } 00141 00142 int mainDialog::mouseOverMod(int x,int y) { 00143 00144 for (int i=0; i<myModList->mods.size(); i++) { 00145 //std::cout << x << " &Y: " << y << std::endl; 00146 //std::cout << x << " &Y: " << y << std::endl; 00147 if ((myModList->mods[i]->x < x) && (myModList->mods[i]->y < y) 00148 && (myModList->mods[i]->x2 > x) && (myModList->mods[i]->y2 > y) ) 00149 { 00150 //std::cout << "X" << std::endl; 00151 return i; 00152 } 00153 00154 } 00155 return -1; 00156 } 00157 00158 00159 00160 00161 mainDialog::mainDialog(Synth * syn) { 00162 ii = 0; 00163 myWindow = new WinForm(460,650, WinForm::standard, "Syntopia - Main window"); 00164 00165 Synth * mySynth = syn; 00166 00167 00168 mySynth->StateChange(); 00169 00170 std::cout << "Updatemap:" << std::endl; 00171 00172 // We only display the modules for one voice 00173 SynthVoice * firstVoice = 0; 00174 myModList = new modList(); 00175 00176 for(ModuleMapIter it = mySynth->totalMap.begin(); it != mySynth->totalMap.end(); ++it) 00177 { 00178 if ((*it)->hostVoice != 0) { 00179 // This module is part of a SynthVoice. 00180 if (firstVoice == 0) { 00181 // It is the first SynthVoice encountered. 00182 firstVoice = (*it)->hostVoice; 00183 } 00184 00185 } 00186 00187 if (((*it)->hostVoice == firstVoice) || ((*it)->hostVoice == 0)) 00188 { 00189 // Only process the first voice 00190 std::cout << "Number I: " << (*it)->getName() << " X: " << (*it)->hostVoice << std::endl; 00191 // Add it to list 00192 myModList->addModule((*it)); 00193 } else 00194 if ((*it)->hostVoice != 0) 00195 { 00196 // This is not the first voice. 00197 int index = myModList->getFirstModule((*it)->ModID); 00198 if (index == -1) { 00199 std::cout << "No matching first voice. " << std::endl; 00200 } else 00201 { 00202 myModList->mods[index]->addModule((*it)); 00203 std::cout << "Added more modules " << (*it)->ModID << " : " << (*it)->getName() << " TO: " << index << std::endl; 00204 } 00205 } 00206 } 00207 00208 00209 00210 myModList->print(); 00211 00212 // Setup Canvas. 00213 00214 modCanvas = new MCanvas(); 00215 modCanvas->PutInWinForm(myWindow, 10,10,430,400); 00216 // Debug: 00217 myText2 = new TextBox(); 00218 myText2->PutInWinForm(myWindow,10,420,430,200); 00219 00220 GUIControl::GUIInstance->ErrorTextBox = myText2; 00221 00222 modCanvas->setEventHandler(this); 00223 00224 myPopup = new popupMenu(modCanvas->getHWND()); 00225 myPopup->setEventHandler(this); 00226 00227 myPopup->add(mItem11 = new menuItem("&Delete Module")); 00228 myPopup->add(mItem12 = new menuItem("&Properties")); 00229 myPopup->add(mItem13 = new menuItem("&Help")); 00230 00231 myPopup2 = new popupMenu(modCanvas->getHWND()); 00232 myPopup2->setEventHandler(this); 00233 00234 myPopup2->add(mItem21 = new menuItem("N&ew Module")); 00235 00236 myWindow->show(); 00237 myText2->addText("Welcome to Syntopia.... Prototype build 0.1"); 00238 myText2->addText(""); 00239 myText2->addText("GUI initialized."); 00240 myText2->addText("Visit http://syntopia.sourceforge.net for more info."); 00241 00242 00243 drawmain(); 00244 } 00245 00246 void mainDialog::MessageLoop() { 00247 // Enter Loop until Exit. 00248 GUIControl::GUIInstance->MessageLoop(); 00249 } 00250 00251 mainDialog::~mainDialog() { 00252 // Clean Up. 00253 delete(myWindow); 00254 } 00255 00256 00257 00258 00259 00260 void mainDialog::HandleEvents(event ev) { 00261 00262 00263 if (ev.EventSource==mItem12) 00264 { int xPos = pt.x; // horizontal position of cursor 00265 int yPos = pt.y; 00266 int sel = mouseOverMod(xPos,yPos); 00267 std::cout << "HELLO:" << xPos << " " << yPos << std::endl; 00268 if (sel != -1) 00269 { myModList->mods[sel]->displayDialog();std::cout << "HELLO" << std::endl; } 00270 drawmain(); 00271 } 00272 00273 if ((ev.EventSource==modCanvas)) 00274 { 00275 if (ev.msg == WM_LBUTTONDOWN) { 00276 00277 int xPos = LOWORD(ev.lParam); // horizontal position of cursor 00278 int yPos = HIWORD(ev.lParam); 00279 00280 int sel = mouseOverMod(xPos,yPos); 00281 if (sel != -1) { 00282 myModList->setChosen(sel); 00283 deltaX = xPos - myModList->mods[sel]->x; 00284 deltaY = yPos - myModList->mods[sel]->y; 00285 } 00286 drawmain(); 00287 } 00288 00289 00290 if (ev.msg == WM_LBUTTONUP) { 00291 myModList->setChosen(-1); 00292 drawmain(); 00293 00294 } 00295 00296 if (ev.msg == WM_RBUTTONDOWN) { 00297 int xPos = LOWORD(ev.lParam); // horizontal position of cursor 00298 int yPos = HIWORD(ev.lParam); 00299 pt.x = xPos; 00300 pt.y = yPos; 00301 int sel = mouseOverMod(xPos,yPos); 00302 00303 //lastChoosen = sel; 00304 //POINT pt; 00305 00306 if (sel!=-1) { 00307 myPopup->showMenu(); 00308 // TrackPopupMenu(hSubMenu, TPM_LEFTALIGN|TPM_TOPALIGN,pt.x,pt.y,0,waveCanvas->getHWND(),NULL); 00309 } else { 00310 myPopup2->showMenu(); 00311 //TrackPopupMenu(hSubMenu2, TPM_LEFTALIGN|TPM_TOPALIGN,pt.x,pt.y,0,waveCanvas->getHWND(),NULL); 00312 } 00313 00314 } 00315 00316 00317 if ((ev.msg == WM_MOUSEMOVE) && (ev.wParam & MK_LBUTTON)) 00318 { 00319 if (myModList->chosen !=-1) { 00320 00321 int xPos = LOWORD(ev.lParam); // horizontal position of cursor 00322 int yPos = HIWORD(ev.lParam); 00323 00324 myModList->mods[myModList->chosen]->x = xPos -deltaX; 00325 myModList->mods[myModList->chosen]->x2 = xPos -deltaX + 100; 00326 myModList->mods[myModList->chosen]->y = yPos -deltaY; 00327 myModList->mods[myModList->chosen]->y2 = yPos -deltaY + 80; 00328 00329 00330 drawmain(); 00331 } 00332 } 00333 00334 } 00335 00336 00337 00338 00339 } 00340 00341 00342 void mod::displayDialog() { 00343 std::cout << "XXXXXXXXX"; 00344 std::string s1("BIQUAD"); 00345 std::string s2("Sampler"); 00346 std::string s3("Envelope3"); 00347 00348 // We do have unsafe typecasts here. Not nice, but the types are checked 00349 // by getName(). 00350 if (mv[0]->getName() == s1) { FilterDialog * myFilter = new FilterDialog(this); }; 00351 if (mv[0]->getName() == s2) { OscDialog * myFilter = new OscDialog(this); }; 00352 if (mv[0]->getName() == s3) { EnvDialog * myFilter = new EnvDialog(this); }; 00353 } 00354 00355 00356 }; // end of namespace: SynthGUI Docs made by Doxygen. Email: Mikael Christensen |