Changeset 1318

Show
Ignore:
Timestamp:
12/20/07 19:38:54 (10 months ago)
Author:
calvin
Message:

zoner: pattern editor updates: customizable note off string, theme colors for note offs and margin text, sticky selections
ld0d: added oscilloscope to AnalyzerView?
calvin: added context menu to AnalyzerView?

Location:
trunk/src/buzelib
Files:
14 modified

Legend:

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

    r1312 r1318  
    2121    bitmapBits = 0; 
    2222    bufferScreenWidth = 0; 
     23        mode = 0; 
    2324    setBufferSize(MAX_FFT_SIZE*2); 
    2425} 
     
    123124} 
    124125 
     126static float fftfunc(float x) 
     127{ 
     128        if(x == 0.0) return 0.0; 
     129 
     130        x = log10(x) * 40.0 - 40; 
     131 
     132        return x; 
     133} 
     134 
     135void AnalyzerView::drawOscilloscope() 
     136{ 
     137        int i, len; 
     138        RECT rect; 
     139        GetClientRect(&rect); 
     140        int _width = rect.right - rect.left; 
     141        int _height = rect.bottom - rect.top; 
     142 
     143        queueCritial.lock(); 
     144        deque<vector<int> > copyQueue = fftQueue; 
     145        fftQueue.clear(); 
     146        queueCritial.unlock(); 
     147 
     148        if (!copyQueue.empty()) { 
     149                vector<int>& points = copyQueue.front(); 
     150 
     151                memset(bitmapBits, 0, _height * _width * sizeof(bitmapBits[0])); 
     152 
     153                len = points.size(); 
     154                if(len > _width) len = _width; 
     155                if(len > 512) len = 512; 
     156 
     157                int y = points[0] * 100 / 32768 + 200; 
     158                if(y < 0) y = 0; 
     159                else if(y >= _height) y = _height - 1; 
     160                int prevy = y; 
     161 
     162                for(i = 0; i < len; i++) { 
     163                        y = points[i] * 100 / 32768 + 200; 
     164                        if(y < 0) y = 0; 
     165                        else if(y >= _height) y = _height - 1; 
     166 
     167                        int sy; 
     168 
     169                        /* draw line: skip first pixel unless ydiff = 0 */ 
     170 
     171                        if(y < prevy) { 
     172                                prevy--; 
     173 
     174                                for(int j = y; j <= prevy; j++) { 
     175                                        bitmapBits[i + j * _width] = RGB(64, 255, 64); 
     176                                } 
     177                        } else if(y > prevy) { 
     178                                prevy++; 
     179 
     180                                for(int j = prevy; j <= y; j++) { 
     181                                        bitmapBits[i + j * _width] = RGB(64, 255, 64); 
     182                                } 
     183                        } else { /* y = prevy */ 
     184                                bitmapBits[i + y * _width] = RGB(64, 255, 64); 
     185                        } 
     186 
     187                        prevy = y; 
     188                } 
     189        } 
     190 
     191        /* draw fft */ 
     192 
     193        int pts = fft.Points() / 2 + 1; 
     194        float scaleHeight = (float)_height / (float)pts;///(float)fft.Points()/2; 
     195        double frqd = (double)pts / (double)_height; 
     196 
     197        if (!copyQueue.empty()) { 
     198 
     199                vector<int>& points = copyQueue.front(); 
     200                fft.Transform(points); 
     201 
     202                if(pts > _width) 
     203                        pts = _width; 
     204 
     205                int y = fftfunc(fft.GetIntensity(0)); 
     206                if(y < 0) y = 0; 
     207                else if(y >= _height) y = _height - 1; 
     208                int prevy = y; 
     209 
     210                for (int i = 0; i < pts; i++) { 
     211 
     212                        y = fftfunc(fft.GetIntensity(i)); 
     213                        if(y < 0) y = 0; 
     214                        else if(y >= _height) y = _height - 1; 
     215 
     216                        int sy; 
     217 
     218                        /* draw line: skip first pixel unless ydiff = 0 */ 
     219 
     220                        if(y < prevy) { 
     221                                prevy--; 
     222 
     223                                for(int j = y; j <= prevy; j++) { 
     224                                        bitmapBits[i + j * _width] = RGB(64, 255, 64); 
     225                                } 
     226                        } else if(y > prevy) { 
     227                                prevy++; 
     228 
     229                                for(int j = prevy; j <= y; j++) { 
     230                                        bitmapBits[i + j * _width] = RGB(64, 255, 64); 
     231                                } 
     232                        } else { /* y = prevy */ 
     233                                bitmapBits[i + y * _width] = RGB(64, 255, 64); 
     234                        } 
     235 
     236                        prevy = y; 
     237                } 
     238                copyQueue.pop_front(); 
     239        } 
     240 
     241        while (!copyQueue.empty()) { 
     242                vector<int>& points = copyQueue.front(); 
     243                fft.Transform(points); 
     244 
     245                copyQueue.pop_front(); 
     246        } 
     247} 
     248 
     249LRESULT AnalyzerView::OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/) { 
     250        return TRUE; 
     251} 
     252 
    125253LRESULT AnalyzerView::OnPaint(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/) { 
    126254 
    127255    if (!background.m_hBitmap) return 0; 
    128256 
    129     drawFft(); 
     257    if (mode == 0) 
     258                drawFft(); else 
     259        if (mode == 1) 
     260                drawOscilloscope(); 
    130261 
    131262    CPaintDC dc(m_hWnd); 
     
    143274} 
    144275 
     276LRESULT AnalyzerView::OnRButtonDown(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& /*bHandled*/) { 
     277        // set up context menu that sends ID_ANALYZER_MODE_FIRST ID_ANALYZER_MODE_FIRST+1 etc 
     278        POINT pt = { LOWORD(lParam), HIWORD(lParam) }; 
     279        CMenu menu;  
     280        menu.CreatePopupMenu(); 
     281        menu.InsertMenu(-1, MF_BYPOSITION|MF_STRING|(mode==0?MF_CHECKED:0), (UINT_PTR)ID_ANALYZER_MODE_FIRST + 0, "Simple"); 
     282        menu.InsertMenu(-1, MF_BYPOSITION|MF_STRING|(mode==1?MF_CHECKED:0), (UINT_PTR)ID_ANALYZER_MODE_FIRST + 1, "Oscilloscope"); 
     283 
     284        ClientToScreen(&pt); 
     285 
     286        menu.TrackPopupMenu(TPM_CENTERALIGN | TPM_LEFTBUTTON, pt.x, pt.y, m_hWnd, 0); 
     287 
     288        return 0; 
     289} 
     290 
     291LRESULT AnalyzerView::OnAnalyzerSetMode(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled) { 
     292        RECT rect; 
     293        GetClientRect(&rect); 
     294        int _width = rect.right - rect.left; 
     295        int _height = rect.bottom - rect.top; 
     296        memset(bitmapBits, 0, _height * _width * sizeof(bitmapBits[0])); 
     297 
     298        WORD type = wID - ID_ANALYZER_MODE_FIRST; 
     299        switch (type) { 
     300                case 0: 
     301                        mode = 0; 
     302                        break; 
     303                case 1: 
     304                        mode = 1; 
     305                        break; 
     306        } 
     307        return 0; 
     308} 
     309 
    145310void AnalyzerView::writeBuffer(float** buffer, size_t numSamples) { 
    146311 
     
    166331} 
    167332 
     333 
  • trunk/src/buzelib/AnalyzerView.h

    r1273 r1318  
    1717    unsigned int* bitmapBits; 
    1818    CBitmap background; 
     19        int mode; 
    1920 
    2021public: 
    21 //      DECLARE_WND_CLASS("WaveTableView") 
     22        DECLARE_WND_CLASS("AnalyzerView") 
    2223//      DECLARE_WND_CLASS_EX("AnalyzerView", CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS, BLACK) 
    2324 
     
    2930                MESSAGE_HANDLER(WM_CLOSE, OnClose) 
    3031                MESSAGE_HANDLER(WM_SETFOCUS, OnFocus) 
     32                MESSAGE_HANDLER(WM_RBUTTONDOWN, OnRButtonDown) 
     33                MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd) 
     34 
     35                COMMAND_RANGE_HANDLER(ID_ANALYZER_MODE_FIRST, ID_ANALYZER_MODE_LAST, OnAnalyzerSetMode) 
    3136        END_MSG_MAP() 
    3237 
     
    3540        ~AnalyzerView(void); 
    3641 
    37         static CWndClassInfo& GetWndClassInfo() { 
    38     static CWndClassInfo wc =  
    39         { { 
    40                 sizeof(WNDCLASSEX), CS_HREDRAW | CS_VREDRAW | CS_DBLCLKS, StartWindowProc,0, 0, NULL, NULL, NULL, (HBRUSH)::GetStockObject(BLACK_BRUSH),NULL,GetWndClassName(), NULL 
    41       }, 
    42       NULL, NULL, IDC_ARROW, TRUE, 0, _T("") 
    43     }; 
    44     return wc; 
    45   } 
    46  
    47   static LPCTSTR GetWndClassName() 
    48   { 
    49     return _T("AnalyzerView"); 
    50   } 
    51  
    5242        LRESULT OnSize(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); 
    5343        LRESULT OnClose(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); 
     
    5545        LRESULT OnPaint(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); 
    5646        LRESULT OnFocus(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); 
     47        LRESULT OnRButtonDown(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); 
     48        LRESULT OnEraseBkgnd(UINT /*uMsg*/, WPARAM /*wParam*/, LPARAM /*lParam*/, BOOL& /*bHandled*/); 
     49        LRESULT OnAnalyzerSetMode(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled); 
    5750 
    5851    void writeBuffer(float** samples, size_t numSamples); 
    5952 
    6053    void drawFft(); 
     54    void drawOscilloscope(); 
    6155        //void work(float* buffer, unsigned int numSamples); 
    6256}; 
  • trunk/src/buzelib/BuzeConfiguration.cpp

    r1313 r1318  
    369369        return atof(str.c_str()); 
    370370} 
     371 
     372std::string CConfiguration::getNoteOffString() { 
     373        string s; 
     374        if (!getConfigString("Settings", "NoteOffString", &s)) 
     375                return "off"; 
     376 
     377        if (s.size() > 3) 
     378                s.resize(3); 
     379        return s; 
     380} 
     381 
     382void CConfiguration::setNoteOffString(std::string s) { 
     383        setConfigString("Settings", "NoteOffString", s); 
     384} 
  • trunk/src/buzelib/BuzeConfiguration.h

    r1313 r1318  
    6868        double getMachineScale(); 
    6969 
     70        void setNoteOffString(std::string s); 
     71        std::string getNoteOffString(); 
     72 
    7073}; 
  • trunk/src/buzelib/Document.h

    r1315 r1318  
    5555 
    5656        UpdateTheme, 
     57        UpdateSettings, 
    5758 
    5859        UpdateClearWave, 
  • trunk/src/buzelib/MachineView.cpp

    r1315 r1318  
    242242                        if (scale<MAX_MACHINE_SCALE) { 
    243243                                scale+=0.1; 
     244                                _Module.configuration->setMachineScale(scale); 
    244245                                invalidateMachines(); 
    245246                        } 
     
    247248                        if (scale>0.3) { 
    248249                                scale-=0.1; 
     250                                _Module.configuration->setMachineScale(scale); 
    249251                                invalidateMachines(); 
    250252                        } 
  • trunk/src/buzelib/MainFrm.cpp

    r1317 r1318  
    16041604        } 
    16051605 
     1606        if (player->getSoloMachine() != 0) 
     1607                document->setMachineSolo(player->getSoloMachine(), FALSE); 
     1608 
    16061609        return 0; 
    16071610} 
     
    28462849        { "PE Text Note", RGB(0x20, 0x20, 0x80) },  
    28472850        { "PE Text Shade", RGB(0x68, 0x68, 0x68) },  
     2851        { "PE Text Margin", RGB(0x7F, 0x73, 0x53) }, 
     2852        { "PE Text Note Off", RGB(0xdd, 0x33, 0xdd) }, 
    28482853        { "SA Amp BG", RGB(0x70, 0x80, 0x90) },  
    28492854        { "SA Amp Line", RGB(0x00, 0xC8, 0x00) },  
     
    29182923} 
    29192924 
     2925void CMainFrame::setDefaultOverrideColor(std::string dest, std::string src) { 
     2926        map<string, COLORREF>::iterator i; 
     2927 
     2928        if (theme.find(dest) != theme.end()) 
     2929                return; 
     2930 
     2931        i = theme.find(src); 
     2932 
     2933        if (i != theme.end()) 
     2934                theme.insert(pair<string, COLORREF>(dest, i->second)); 
     2935} 
     2936 
    29202937void CMainFrame::setTheme(std::string themeName) { 
    29212938 
    29222939        theme.clear(); 
    29232940 
    2924         for (unsigned int i = 0; i< defaultThemeCount; i++) { 
    2925                 theme.insert(pair<string, COLORREF>(defaultTheme[i].name, defaultTheme[i].color)); 
    2926         } 
    29272941 
    29282942        FileReader reader; 
    29292943        string fileName = "Themes/" + themeName + ".col"; 
    2930         if (!reader.open(fileName.c_str())) goto finishTheme; 
    2931  
    2932         while (!reader.eof()) { 
    2933                 std::string line=trim(reader.readLine()); 
    2934                 if (line.length()==0) continue; 
    2935                 if (line.at(0)=='#') continue; 
    2936                  
    2937                 size_t lt = line.find_first_of('\t'); 
    2938                 if (lt == string::npos) continue; 
    2939  
    2940                 string name = trim(line.substr(0, lt)); 
    2941                 string colorstr = trim(line.substr(lt+1)); 
    2942                 if (colorstr.length() != 6) continue; 
    2943  
    2944                 COLORREF color = RGB( 
    2945                         intFromHex(colorstr.substr(0, 2)), 
    2946                         intFromHex(colorstr.substr(2, 2)), 
    2947                         intFromHex(colorstr.substr(4, 2)) 
    2948                 ); 
    2949                 theme[name] = color;//.insert(pair<string, COLORREF>(name, color)); 
    2950         } 
    2951          
    2952         reader.close(); 
    2953  
    2954 finishTheme: 
     2944        if (reader.open(fileName.c_str())) { 
     2945 
     2946                while (!reader.eof()) { 
     2947                        std::string line=trim(reader.readLine()); 
     2948                        if (line.length()==0) continue; 
     2949                        if (line.at(0)=='#') continue; 
     2950                         
     2951                        size_t lt = line.find_first_of('\t'); 
     2952                        if (lt == string::npos) continue; 
     2953 
     2954                        string name = trim(line.substr(0, lt)); 
     2955                        string colorstr = trim(line.substr(lt+1)); 
     2956                        if (colorstr.length() != 6) continue; 
     2957 
     2958                        COLORREF color = RGB( 
     2959                                intFromHex(colorstr.substr(0, 2)), 
     2960                                intFromHex(colorstr.substr(2, 2)), 
     2961                                intFromHex(colorstr.substr(4, 2)) 
     2962                        ); 
     2963                        theme[name] = color; 
     2964                } 
     2965                reader.close(); 
     2966        } 
     2967 
     2968#if 0 // Uncomment this so that legacy buzz themes look their best with buze's new theme values 
     2969 
     2970        // Theme-based defaults 
     2971 
     2972        setDefaultOverrideColor("PE Text Note",         "PE Text"); 
     2973        setDefaultOverrideColor("PE Text Note Off",     "PE Text"); 
     2974        setDefaultOverrideColor("PE Text Shade",        "PE Text"); 
     2975        setDefaultOverrideColor("PE Text Margin",       "PE Text Note"); 
     2976 
     2977#endif 
     2978 
     2979        // Defaults 
     2980 
     2981        for (unsigned int i = 0; i< defaultThemeCount; i++) { 
     2982                if (theme.find(defaultTheme[i].name) == theme.end()) 
     2983                        theme.insert(pair<string, COLORREF>(defaultTheme[i].name, defaultTheme[i].color)); 
     2984        } 
     2985 
    29552986        document->updateAllViews(0, UpdateTheme); 
    29562987 
  • trunk/src/buzelib/MainFrm.h

    r1315 r1318  
    562562        std::string getThemeName(size_t index); 
    563563        void setTheme(std::string theme); 
     564        void setDefaultOverrideColor(std::string dest, std::string src); 
    564565        COLORREF getThemeColor(std::string name); 
    565566 
  • trunk/src/buzelib/PatternEditor/PatternEditorControl.cpp

    r1315 r1318  
    3333        screenDC.SelectFont(editor.track_font); 
    3434        screenDC.SetBkColor(bgcolor); 
    35         screenDC.SetTextColor(editor.colors[PE_TextNote]); 
     35        screenDC.SetTextColor(editor.colors[PE_TextMargin]); 
    3636 
    3737        // render row numbers 
  • trunk/src/buzelib/PatternEditor/PatternEditorInner.cpp

    r1303 r1318  
    2323} 
    2424 
    25 std::string noteFromInt(unsigned char i) { 
    26         if (i == 255) return "off"; 
     25std::string noteFromInt(unsigned char i, std::string noteOffStr) { 
     26        if (i == 255) return noteOffStr; 
    2727        char* notes[]={"..", "C-", "C#", "D-", "D#", "E-", "F-", "F#", "G-", "G#", "A-", "A#", "B-", "..", "..", "..", ".." }; 
    2828        char pc[16]; 
     
    6565        step = 1; 
    6666        last_play_pos = -1; 
     67        noteOffStr = "off"; 
     68        stickySelection = false; 
    6769 
    6870        SetThemeColor(PE_BG, RGB(0xDA, 0xD6, 0xC9)); 
     
    151153                        if (v == columns[j].novalue) 
    152154                                dc.SetTextColor(colors[PE_TextShade]); else 
    153                         if (columns[j].type == pattern_column_type_note) 
    154                                 dc.SetTextColor(colors[PE_TextNote]); else 
    155                                 dc.SetTextColor(colors[PE_TextValue]); 
     155                        if (columns[j].type == pattern_column_type_note) { 
     156                                if (v == 255) // This represents a note off 
     157                                        dc.SetTextColor(colors[PE_TextNoteOff]); 
     158                                else 
     159                                        dc.SetTextColor(colors[PE_TextNote]); 
     160                        } 
     161                        else dc.SetTextColor(colors[PE_TextValue]); 
    156162 
    157163                        int dest_x = columns[j].unit * font_size.cx; 
     
    663669        switch (type) { 
    664670                case pattern_column_type_note: 
    665                         return v!=novalue?noteFromInt(v):"..."; 
     671                        return v!=novalue?noteFromInt(v, noteOffStr):"..."; 
    666672                case pattern_column_type_byte: 
    667673                        return v!=novalue?hexFromInt(v, 2, '0'):".."; 
     
    919925        if (affectsel) { 
    920926                if (IsShiftDown()) { 
     927                        if (stickySelection == true) { 
     928                                if (cursor_columns[last_cursor.x].column < select_start.x || 
     929                                        cursor_columns[last_cursor.x].column > select_end.x || 
     930                                        last_cursor.y < select_start.y || 
     931                                        last_cursor.y > select_end.y) 
     932                                { 
     933                                        InvalidateSelection(); 
     934                                        SelectRange(-1, -1, -1, -1); 
     935                                } 
     936                        } 
    921937                        if (select_first.x == -1) { 
    922938                                // begin selection 
     
    928944                } else { 
    929945                        if (select_first.x != -1) { 
    930                                 SelectRange(-1, -1, -1, -1); 
     946                                if (stickySelection == false) 
     947                                        SelectRange(-1, -1, -1, -1); 
    931948                        } 
    932949                } 
     
    10721089        if (!m_hWnd) return ; 
    10731090 
     1091        InvalidateSelection(&rcPrevSel); 
     1092} 
     1093 
     1094void CPatternEditorInner::InvalidateSelection(RECT *rcPrevSel) { 
    10741095        RECT rcSel; 
     1096         
     1097        if(!rcPrevSel) 
     1098                rcPrevSel = &rcSel; 
     1099 
    10751100        if (!GetSelectionRectScreen(&rcSel)) 
    10761101                rcSel.left = -1; 
    10771102 
    1078         if (rcSel.left != -1 && rcPrevSel.left != -1) { 
    1079                 UnionRect(&rcSel, &rcSel, &rcPrevSel); 
     1103        if (rcSel.left != -1 && rcPrevSel->left != -1) { 
     1104                UnionRect(&rcSel, &rcSel, rcPrevSel); 
    10801105        } else  
    10811106        if (rcSel.left == -1) { 
    1082                 rcSel = rcPrevSel; 
     1107                rcSel = *rcPrevSel; 
    10831108        } 
    10841109 
     
    11121137void CPatternEditorInner::SetThemeColor(theme_index index, COLORREF color) { 
    11131138        colors[index] = color; 
     1139} 
     1140 
     1141void CPatternEditorInner::SetNoteOffStr(std::string s) { 
     1142        noteOffStr = s; 
     1143         
     1144} 
     1145 
     1146void CPatternEditorInner::SetStickySelection(bool setting) { 
     1147        stickySelection = setting; 
    11141148} 
    11151149 
  • trunk/src/buzelib/PatternEditor/PatternEditorInner.h

    r1263 r1318  
    7474        PE_TextNote = 6, 
    7575        PE_TextValue = 7, 
     76        PE_TextNoteOff = 8, 
     77        PE_TextMargin = 9, 
     78 
    7679}; 
    7780 
    7881class CPatternEditorInner : public CWindowImpl<CPatternEditorInner> { 
    7982public: 
    80         COLORREF colors[8]; 
     83        COLORREF colors[10]; 
    8184        SIZE font_size, pattern_size; 
    8285        RECT rcClient; 
     
    8891        CBitmap pattern_bitmap; 
    8992        CFont track_font; 
     93        std::string noteOffStr; 
     94        bool stickySelection; 
    9095 
    9196        int rows, total_rows; 
     
    152157        void SetFont(HFONT hFont, bool bRedraw = 1); 
    153158        void SetThemeColor(theme_index index, COLORREF color); 
     159        void SetNoteOffStr(std::string s); 
     160        void SetStickySelection(bool setting); 
    154161        void MoveCursor(int x, int y, bool affectsel); 
    155162        void ScrollTo(POINT pt);                // scroll to position pt 
     
    159166        bool GetRangeRectScreen(int from_col, int from_row, int to_col, int to_row, RECT* rc); 
    160167        bool GetSelectionRect(RECT* rc); 
     168        void InvalidateSelection(RECT *rcPrevSel = NULL); 
    161169        void SetHighlightRows(int verydarkrow, int darkrow); 
    162170        void SelectRange(int from_col, int from_row, int to_col, int to_row); 
  • trunk/src/buzelib/PatternView.cpp

    r1314 r1318  
    224224        setPatternEditorFont(); 
    225225 
     226        bindSettings(); 
    226227        bindTheme(); 
    227228        bindPatternEditor(); 
     
    574575                        break; 
    575576                } 
     577                case UpdateSettings: 
     578                        bindSettings(); 
     579                        break;