Changeset 1297

Show
Ignore:
Timestamp:
11/01/07 13:55:14 (10 months ago)
Author:
calvin
Message:

optimized machine view, wave export works with >16 bits, fix crashes when stream plugin wasnt found

Location:
trunk/src/buzelib
Files:
6 modified

Legend:

Unmodified
Added
Removed
  • trunk/src/buzelib/Document.cpp

    r1293 r1297  
    5656                streamplayer->initialize(0, 0, 0, 0, 0); 
    5757                player->master->addAudioInput(streamplayer, 0x4000, 0x4000); 
     58                streamplayer->nonSongPlugin = true; 
    5859        } else { 
    5960                streamplayer = 0; 
    60         } 
    61  
    62         if (!streamplayer) 
    63                 printf("Cant can't create streamplayer plugin instance.\n"); else 
    64                 streamplayer->nonSongPlugin = true; 
     61                printf("Cant can't create streamplayer plugin instance.\n"); 
     62        } 
    6563} 
    6664 
  • trunk/src/buzelib/FileBrowserView.cpp

    r1293 r1297  
    204204        if (selectedFiles.size() == 0) return 0; 
    205205 
     206        if (!mainFrame->document->streamplayer) return 0; 
     207 
    206208        CFileInfo* fileInfo = selectedFiles[0]; 
    207209        if (mainFrame->document->isNotePlaying(mainFrame->document->streamplayer, note)) return 0; 
     
    233235        if (note == -1) return 0; 
    234236 
     237        if (!mainFrame->document->streamplayer) return 0; 
    235238        mainFrame->document->playMachineNote(mainFrame->document->streamplayer, zzub::note_value_off, note); 
    236239        return 0; 
  • trunk/src/buzelib/MachineView.cpp

    r1281 r1297  
    1616#include <iomanip> 
    1717#include <strstream> 
     18#include <limits> 
    1819#include "Utils/Keymaps.h" 
    1920 
     
    3940        isConnecting = false; 
    4041        isPanSlider = false; 
    41         redrawMode = MachineViewAll; 
    4242        mbuttonState = false; 
    4343        isLButtonDown = false; 
     
    4545        moveType = MachineViewMoveNothing; 
    4646        SetRect(&prevDragRect, -1, -1, -1, -1); 
     47 
     48        dirtyOffscreenBitmap = true; 
     49        dirtyMachines = dirtySelectionRectangle = dirtyStatus = dirtyVolumeSlider = false; 
    4750} 
    4851 
     
    455458} 
    456459 
     460void minMaxRect(RECT* rcOut, RECT* rcIn) { 
     461        if (rcIn->left < rcOut->left) 
     462                rcOut->left = rcIn->left; 
     463        if (rcIn->top < rcOut->top) 
     464                rcOut->top = rcIn->top; 
     465        if (rcIn->right > rcOut->right) 
     466                rcOut->right = rcIn->right; 
     467        if (rcIn->bottom > rcOut->bottom) 
     468                rcOut->bottom = rcIn->bottom; 
     469} 
     470 
    457471LRESULT CMachineView::OnMouseMove(UINT /*uMsg*/, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/) { 
    458472 
    459         //if (draggingMachine && isConnecting) { 
    460473        if (moveType==MachineViewMoveConnectMachines) { 
    461474                if (((wParam&MK_SHIFT) != 0) || mbuttonState ) { 
     
    472485        } else 
    473486        if (moveType==MachineViewMovePanSlider) { 
    474 //      if (draggingMachine && isPanSlider) { 
    475487                // adjust panning = calculate pan value 
    476488                POINT pt={(signed short)LOWORD(lParam),(signed short)HIWORD(lParam)}; 
     
    495507        } else 
    496508        if (moveType==MachineViewMoveSelectedMachines) { 
    497 //      if (draggingMachine) { 
    498509                POINT ppt={offX, offY}; 
    499510                POINT pt={(signed short)LOWORD(lParam),(signed short)HIWORD(lParam)}; 
     
    507518                if (fabs(mdx)==0 && fabs(mdy)==0) return 0; 
    508519 
    509                 // todo: her skal vi egentlig sette posisjon på alle valgte maskiner 
    510                 // så, vi finner deltaet som denne maskinen flytter seg 
     520                RECT rcInvalidate = {  
     521                        0x10000000, 0x10000000,  
     522                        -0x10000000, -0x10000000,  
     523                }; 
     524 
     525                // move the selected machines, and find the smallest area on screen  
     526                // that needs to be repainted 
    511527                for (int i=0; i<document->getSelectedMachines(); i++) { 
    512                         document->getSelectedMachine(i)->x+=mdx; 
    513                         document->getSelectedMachine(i)->y+=mdy; 
    514                 } 
    515                 invalidateMachines(); 
    516                 offX=pt.x; 
    517                 offY=pt.y; 
     528                        RECT selrc; 
     529                        zzub::metaplugin* selplugin = document->getSelectedMachine(i); 
     530                        getMachineRect(selplugin, &selrc); 
     531                        InflateRect(&selrc, 3, 3); 
     532                        minMaxRect(&rcInvalidate, &selrc); 
     533 
     534                        selplugin->x += mdx; 
     535                        selplugin->y += mdy; 
     536 
     537                        getMachineRect(selplugin, &selrc); 
     538                        InflateRect(&selrc, 3, 3); 
     539                        minMaxRect(&rcInvalidate, &selrc); 
     540 
     541                        // make sure the invalidation rect covers all machines we are connected to 
     542                        for (int j = 0; j < selplugin->inConnections.size(); j++) { 
     543                                metaplugin* selconnplugin = selplugin->inConnections[j]->plugin_in; 
     544                                if (selconnplugin->nonSongPlugin) continue; 
     545 
     546                                getMachineRect(selconnplugin, &selrc); 
     547                                InflateRect(&selrc, 3, 3); 
     548                                minMaxRect(&rcInvalidate, &selrc); 
     549                        } 
     550 
     551                        for (int j = 0; j < selplugin->outConnections.size(); j++) { 
     552                                metaplugin* selconnplugin = selplugin->outConnections[j]->plugin_out; 
     553                                if (selconnplugin->nonSongPlugin) continue; 
     554 
     555                                getMachineRect(selconnplugin, &selrc); 
     556                                InflateRect(&selrc, 3, 3); 
     557                                minMaxRect(&rcInvalidate, &selrc); 
     558                        } 
     559                } 
     560                dirtyMachines = true; 
     561                InvalidateRect(&rcInvalidate, FALSE); 
     562                offX = pt.x; 
     563                offY = pt.y; 
    518564        } else 
    519565        if (moveType==MachineViewMoveVolumeSlider) { 
    520         //if (isVolumeSlider) { 
    521                 // change connection amp 
    522566                POINT pt={(signed short)LOWORD(lParam),(signed short)HIWORD(lParam)}; 
    523567        int dist=offY-pt.y; 
     
    539583        } else 
    540584        if (moveType==MachineViewMoveAllMachines) { 
    541 //      if (isLButtonDown && isCtrlDown()) { 
    542585                POINT ppt={offX, offY}; 
    543586                POINT pt={(signed short)LOWORD(lParam),(signed short)HIWORD(lParam)}; 
     
    672715 
    673716LRESULT CMachineView::OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) { 
     717 
    674718        CPaintDC screenDC(m_hWnd); 
    675          
    676         if (redrawMode==MachineViewSelectionRectangle) { 
    677                 // if we only update the selection rectangle, draw directly to mr screen 
    678                 paintSelectionRect(screenDC); 
    679         } else { 
    680                 CMemDC dc(screenDC); 
    681  
    682                 if (redrawMode&MachineViewBoxes) 
    683                         paintMachines(dc); 
    684  
    685                 if (redrawMode&MachineViewStatus) 
    686                         paintMachineStatus(dc); 
    687  
    688                 if (redrawMode&MachineViewVolume) 
    689                         paintVolume(dc); 
    690  
    691                 if (redrawMode&MachineViewSelectionRectangle) 
    692                         paintSelectionRect(dc); 
    693         } 
    694  
    695  
     719 
     720        CDC offscreenDC; 
     721        offscreenDC.CreateCompatibleDC(screenDC); 
     722 
     723        RECT rcClip; 
     724        screenDC.GetClipBox(&rcClip); 
     725 
     726        if (dirtyOffscreenBitmap) { 
     727                if (offscreenBitmap.m_hBitmap) 
     728                        offscreenBitmap.DeleteObject(); 
     729 
     730                RECT rcClient; 
     731                GetClientRect(&rcClient); 
     732                offscreenBitmap.CreateCompatibleBitmap(screenDC, rcClient.right, rcClient.bottom); 
     733 
     734                dirtyMachines = true; 
     735                dirtyOffscreenBitmap = false; 
     736 
     737        } 
     738 
     739        CBitmapHandle oldbitmap = offscreenDC.SelectBitmap(offscreenBitmap); 
     740 
     741        if (dirtyMachines) { 
     742                offscreenDC.FillSolidRect(rcClip.left, rcClip.top, rcClip.right - rcClip.left, rcClip.bottom - rcClip.top, backgroundColor); 
     743                paintMachines(offscreenDC); 
     744                dirtyStatus = true; 
     745        } 
     746 
     747        if (dirtyStatus) 
     748                paintMachineStatus(offscreenDC); 
     749 
     750        if (dirtyVolumeSlider) 
     751                paintVolume(offscreenDC); 
     752 
     753        if (dirtySelectionRectangle) 
     754                paintSelectionRect(offscreenDC); 
     755 
     756 
     757        dirtyMachines = dirtySelectionRectangle = dirtyStatus = dirtyVolumeSlider = false; 
     758 
     759    screenDC.BitBlt( 
     760                rcClip.left, rcClip.top, rcClip.right - rcClip.left, rcClip.bottom - rcClip.top, 
     761                offscreenDC, rcClip.left, rcClip.top, SRCCOPY); 
     762 
     763        offscreenDC.SelectBitmap(oldbitmap); 
     764 
     765        return 0; 
     766} 
     767 
     768LRESULT CMachineView::OnSize(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/) { 
     769        dirtyOffscreenBitmap = true; 
     770        Invalidate(FALSE); 
    696771        return 0; 
    697772} 
     
    725800        prevDragRect = rc; 
    726801} 
    727  
    728  
    729  
    730802 
    731803void CMachineView::showMachineContext(POINT pt, metaplugin* machine) { 
     
    10241096 
    10251097void CMachineView::invalidateMachines() { 
    1026         redrawMode=MachineViewAll; 
     1098        dirtyMachines = true; 
    10271099        Invalidate(FALSE); 
    1028         UpdateWindow(); 
    1029         redrawMode=MachineViewAll; 
    10301100} 
    10311101 
    10321102void CMachineView::invalidateConnectionVolume() { 
    1033         redrawMode=MachineViewVolume; 
    1034  
    1035         connection* conn=document->getSelectedConnection(); 
     1103        dirtyVolumeSlider = true; 
     1104 
     1105        connection* conn = document->getSelectedConnection(); 
    10361106 
    10371107        RECT vsr; 
    10381108        getVolumeSliderRect(conn, &vsr); 
    10391109        InvalidateRect(&vsr, FALSE); 
    1040  
    1041         UpdateWindow(); 
    1042         redrawMode=MachineViewAll; 
    1043  
    10441110} 
    10451111 
    10461112void CMachineView::invalidateSelectionRectangle() { 
    1047         redrawMode=MachineViewSelectionRectangle; 
    1048  
     1113        dirtySelectionRectangle = true; 
    10491114        Invalidate(FALSE); 
    1050  
    1051         UpdateWindow(); 
    1052         redrawMode=MachineViewAll; 
    1053  
    10541115} 
    10551116 
    10561117void CMachineView::invalidateStatus() { 
    1057         redrawMode=MachineViewStatus; 
    1058  
    1059         for (size_t i=0; i<player->getMachines(); i++) { 
    1060                 metaplugin* machine=player->getMachine(i); 
     1118        dirtyStatus = true; 
     1119 
     1120        for (size_t i = 0; i < player->getMachines(); i++) { 
     1121                metaplugin* machine = player->getMachine(i); 
    10611122                if (!machine) continue; 
    10621123                if (machine->nonSongPlugin) continue; 
     
    10651126                InvalidateRect(&rc, FALSE); 
    10661127        } 
    1067  
    1068         UpdateWindow(); 
    1069         redrawMode=MachineViewAll; 
    1070  
    10711128} 
    10721129 
    10731130void CMachineView::invalidateMachine(metaplugin* machine) { 
     1131        dirtyMachines = true; 
     1132 
    10741133        RECT rc; 
    10751134        getMachineRect(machine, &rc); 
    1076         redrawMode=MachineViewBoxes; 
    10771135        InvalidateRect(&rc, FALSE); 
    10781136} 
     
    12431301        getMachineRect(plugin, &mRect); 
    12441302         
    1245         int fontIndex=(scale/MAX_MACHINE_SCALE)*((float)MAX_MACHINE_FONTS-0.5); 
    1246         CFont prevFont=dc.SelectFont(machineFont[fontIndex]); 
    1247  
    1248         UINT prevAlign=dc.SetTextAlign(TA_CENTER); 
    1249         int prevBkMode=dc.SetBkMode(TRANSPARENT); 
    1250  
    12511303        // draw outer box 
    12521304        CPenHandle oldPen = dc.SelectPen(borderPen); 
    12531305        CBrushHandle oldBrush = dc.SelectBrush(getMachineBrush(plugin)); 
    1254         dc.Rectangle(mRect.left, mRect.top, mRect.right, mRect.bottom); 
    12551306         
    12561307        MachineSkin* skin = mainFrame->getSkin(plugin->loader->plugin_info->uri); 
     
    12621313                ::GetObject(skin->skin, sizeof(BITMAP), &bm); 
    12631314                dc.StretchBlt(mRect.left, mRect.top, halfWidth*2, halfHeight*2, bitmapDC, 0, 0, bm.bmWidth, bm.bmHeight, SRCCOPY); 
    1264         } 
    1265  
    1266         connection* masterConnection=player->getMaster()->getConnection(plugin); 
    1267         // hvis denne går til master, så tegner vi connection-panning-fixing: 
    1268         if (masterConnection) { 
    1269                 // draw panning box inside normal box 
    1270                 dc.SelectBrush(getMachinePanningBrush(plugin)); 
    1271                 dc.Rectangle(mRect.left+2, mRect.bottom-(10.0*scale), mRect.right-2, mRect.bottom-2); 
    1272      
    1273                 // and the little pan-slider: 
    1274  
    1275                 RECT pRect; 
    1276                 dc.SelectBrush(panHandleBrush); 
    1277                 getPanSliderRect(masterConnection, &pRect); 
    1278                 dc.Rectangle(&pRect); 
    1279         } 
    1280  
    1281         string label=plugin->getName(); 
    1282         if (player->getSoloMachine()!=0 && player->getSoloMachine()!=plugin) 
    1283                 label="["+label+"]"; 
    1284  
    1285         if (plugin->isMuted()) 
    1286                 label="("+label+")"; 
    1287  
    1288         float fontSize=(scale+1)*8; 
    1289  
    1290         int adjustY=plugin->minimized?-fontSize:0; 
    1291  
    1292         if (skin && skin->skin && !plugin->minimized) 
    1293                 dc.SetTextColor(skin->textColor); else 
    1294                 dc.SetTextColor(0); 
    1295         dc.TextOut(mRect.left+halfWidth, mRect.top+halfHeight-(fontSize/2)+adjustY, label.c_str(), label.length()); 
    1296  
    1297         if (!ledOnly && document->isSelectedMachine(plugin)) { 
    1298                 RECT fRect = mRect; 
    1299                 fRect.left -= 2; 
    1300                 fRect.top -= 2; 
    1301                 fRect.right += 2; 
    1302                 fRect.bottom += 2; 
    1303                 dc.SetTextColor(0); 
    1304                 dc.DrawFocusRect(&fRect); 
    1305                 InflateRect(&fRect, 1, 1); 
    1306                 dc.DrawFocusRect(&fRect); 
     1315        } else { 
     1316                dc.Rectangle(mRect.left, mRect.top, mRect.right, mRect.bottom); 
     1317        } 
     1318 
     1319        if (!ledOnly) { 
     1320 
     1321                connection* masterConnection=player->getMaster()->getConnection(plugin); 
     1322                // hvis denne går til master, så tegner vi connection-panning-fixing: 
     1323                if (masterConnection) { 
     1324                        // draw panning box inside normal box 
     1325                        dc.SelectBrush(getMachinePanningBrush(plugin)); 
     1326                        dc.Rectangle(mRect.left+2, mRect.bottom-(10.0*scale), mRect.right-2, mRect.bottom-2); 
     1327             
     1328                        // and the little pan-slider: 
     1329 
     1330                        RECT pRect; 
     1331                        dc.SelectBrush(panHandleBrush); 
     1332                        getPanSliderRect(masterConnection, &pRect); 
     1333                        dc.Rectangle(&pRect); 
     1334                } 
     1335 
     1336        // draw machine label 
     1337                int fontIndex=(scale/MAX_MACHINE_SCALE)*((float)MAX_MACHINE_FONTS-0.5); 
     1338                CFont prevFont=dc.SelectFont(machineFont[fontIndex]); 
     1339 
     1340                UINT prevAlign=dc.SetTextAlign(TA_CENTER); 
     1341                int prevBkMode=dc.SetBkMode(TRANSPARENT); 
     1342 
     1343 
     1344                string label=plugin->getName(); 
     1345                if (player->getSoloMachine()!=0 && player->getSoloMachine()!=plugin) 
     1346                        label="["+label+"]"; 
     1347 
     1348                if (plugin->isMuted()) 
     1349                        label="("+label+")"; 
     1350 
     1351                float fontSize=(scale+1)*8; 
     1352 
     1353                int adjustY=plugin->minimized?-fontSize:0; 
     1354 
     1355                if (skin && skin->skin && !plugin->minimized) 
     1356                        dc.SetTextColor(skin->textColor); else 
     1357                        dc.SetTextColor(0); 
     1358                dc.TextOut(mRect.left+halfWidth, mRect.top+halfHeight-(fontSize/2)+adjustY, label.c_str(), label.length()); 
     1359 
     1360 
     1361                if (document->isSelectedMachine(plugin)) { 
     1362                        RECT fRect = mRect; 
     1363                        fRect.left -= 2; 
     1364                        fRect.top -= 2; 
     1365                        fRect.right += 2; 
     1366                        fRect.bottom += 2; 
     1367                        dc.SetTextColor(0); 
     1368                        dc.DrawFocusRect(&fRect); 
     1369                        InflateRect(&fRect, 1, 1); 
     1370                        dc.DrawFocusRect(&fRect); 
     1371                } 
     1372                dc.SetTextAlign(prevAlign); 
     1373                dc.SetBkMode(prevBkMode); 
     1374                dc.SelectFont(prevFont); 
    13071375        } 
    13081376 
    13091377        dc.SelectPen(oldPen); 
    13101378        dc.SelectBrush(oldBrush); 
    1311         dc.SetTextAlign(prevAlign); 
    1312         dc.SetBkMode(prevBkMode); 
    1313         dc.SelectFont(prevFont); 
    13141379 
    13151380} 
    13161381 
    13171382void CMachineView::paintMachines(CDC& dc) { 
    1318         RECT rc; 
    1319         GetClientRect(&rc); 
    1320         dc.FillSolidRect(0,0, rc.right, rc.bottom, backgroundColor); 
    13211383 
    13221384        CPenHandle oldPen = dc.SelectPen(linePen); 
  • trunk/src/buzelib/MachineView.h

    r1281 r1297  
    99class CMainFrame; 
    1010class ClientViewListener; 
    11  
    12 enum MachineViewRedraw { 
    13         MachineViewBoxes=1, 
    14         MachineViewStatus=2, 
    15         MachineViewVolume=4, 
    16         MachineViewSelectionRectangle=8, 
    17  
    18         MachineViewAll=MachineViewBoxes|MachineViewStatus, 
    19         MachineViewAllSelection=MachineViewBoxes|MachineViewStatus|MachineViewSelectionRectangle 
    20 }; 
    2111 
    2212enum MachineViewMouseMoveType { 
     
    3828        ClientViewListener* clientViewListener; 
    3929        zzub::player* player; 
    40         MachineViewRedraw redrawMode; 
    4130 
    4231        zzub::metaplugin* draggingMachine; 
     
    7766        CBrush ampHandleBrush; 
    7867 
     68        bool dirtyMachines, dirtyStatus, dirtySelectionRectangle, dirtyVolumeSlider; 
     69        bool dirtyOffscreenBitmap; 
     70        CBitmap offscreenBitmap; 
    7971public: 
    8072        double scale; 
     
    8880                MESSAGE_HANDLER(WM_PAINT, OnPaint) 
    8981                MESSAGE_HANDLER(WM_CHAR, OnChar) 
     82                MESSAGE_HANDLER(WM_SIZE, OnSize) 
    9083                MESSAGE_HANDLER(WM_KEYDOWN, OnKeyDown) 
    9184                MESSAGE_HANDLER(WM_KEYUP, OnKeyUp) 
     
    125118        LRESULT OnCreate(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); 
    126119        LRESULT OnFocus(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); 
     120        LRESULT OnSize(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); 
    127121        LRESULT OnKeyDown(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); 
    128122        LRESULT OnKeyUp(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); 
  • trunk/src/buzelib/MainFrm.cpp

    r1295 r1297  
    23382338                return 0; 
    23392339        zzub::wave_level* wavelevel = wave->get_level(level); 
    2340         sf_writef_short(sf, (const short*)wave->get_sample_ptr(level), wave->get_sample_count(level)); 
     2340        sf_write_raw(sf, wave->get_sample_ptr(level), wave->get_sample_count(level) * ( wave->get_bits_per_sample(level) / 8 * sfinfo.channels ) ); 
    23412341        sf_close(sf); // so close it 
    23422342        return 1; 
  • trunk/src/buzelib/WaveTableView.cpp

    r1294 r1297  
    446446        if (index < 0) return 0; 
    447447 
     448        if (!document->streamplayer) return 0; 
    448449        if (document->isNotePlaying(document->streamplayer, note)) return 0; 
    449450 
     
    457458        if (note == -1) return 0; 
    458459 
     460        if (!document->streamplayer) return 0; 
    459461        document->playMachineNote(document->streamplayer, zzub::note_value_off, note); 
    460462        return 0;