Пример #1
0
const int OCPiano::PitchToPos(const int Pitch)
{
    int X=(IntDiv(Pitch, 12)*7)-1;
    switch (Pitch % 12)
    {
    case 2:
    case 3:
        X+=1;
        break;
    case 4:
        X+=2;
        break;
    case 5:
    case 6:
        X+=3;
        break;
    case 7:
    case 8:
        X+=4;
        break;
    case 9:
    case 10:
       X+=5;
       break;
    case 11:
        X+=6;
        break;
    }
    X*=WhiteKeyWidth;
    if (IsBlackKey(Pitch)) X+=BlackKeyOffset;
    return X+5;
}
Пример #2
0
void OCPiano::DrawKey(const int Pitch, const bool Pressed)
{
    int Pos=PitchToPos(Pitch);
    if (IsBlackKey(Pitch))
    {
        DrawBlackKey(Pos,Pressed);
    }
    else
    {
        DrawWhiteKey(Pos,Pressed);
    }
}
Пример #3
0
void OCPiano::Paint()
{
    //Scene.clear();
    ClearTransparent();
    for (int i=1;i<128;i++)
    {
        if (!IsBlackKey(i)) DrawKey(i,Pitches.contains(i) || (i==CurrentPitch));
    }
    for (int i=1;i<128;i++)
    {
        if (IsBlackKey(i)) DrawKey(i,Pitches.contains(i) || (i==CurrentPitch));
    }

    SetPenBrush(Qt::black,Qt::darkGray);
    QPainterPath p(QPoint(PitchToPos(60)+2,WhiteKeyHeight+5));
    p.lineTo(PitchToPos(60)+2+((WhiteKeyWidth-4)/2),WhiteKeyHeight);
    p.lineTo(PitchToPos(60)+WhiteKeyWidth-2,WhiteKeyHeight+5);
    Path(p);

    //Scene.addPath(p,QPen(Qt::black),QBrush(Qt::darkGray));
    //this->viewport()->update();
    update();
}
Пример #4
0
 void OnPaint()
 {
     wxPaintDC dc(this);
     
     auto rect = GetClientRect();
     
     dc.SetPen(wxPen(wxColor(0x26, 0x1E, 0x00)));
     dc.SetBrush(wxBrush(wxColor(0x26, 0x1E, 0x00)));
     dc.DrawRectangle(rect);
     
     int const disp_half = rect.GetWidth() / 2;
     int const disp_shift = kFullKeysWidth / 2 - disp_half;
     
     auto draw_key = [&](auto note_num, auto const &prop, auto const &img) {
         int const octave = note_num / 12;
         auto key_rect = prop.rect_;
         key_rect.Offset(octave * kKeyWidth * 7 - disp_shift, 0);
         
         if(key_rect.GetLeft() >= rect.GetWidth()) { return; }
         if(key_rect.GetRight() < 0) { return; }
         
         dc.DrawBitmap(wxBitmap(img), key_rect.GetTopLeft());
         
         //            if(is_playing) {
         //                col_pen = kKeyBorderColorPlaying;
         //                col_brush = kPlayingNoteColor;
         //                dc.SetPen(wxPen(col_pen));
         //                dc.SetBrush(wxBrush(col_brush));
         //            }
         //            dc.DrawRoundedRectangle(key_rect, 2);
     };
     
     for(int i = 0; i < kNumKeys; ++i) {
         if(IsWhiteKey(i) == false) { continue; }
         
         bool const is_playing = playing_notes_[i];
         bool next_pushed = false;
         if(i < kNumKeys - 2) {
             if(IsWhiteKey(i+1) && playing_notes_[i+1]) { next_pushed = true; }
             else if(IsWhiteKey(i+2) && playing_notes_[i+2]) { next_pushed = true; }
         }
         
         auto const &img
         = (is_playing && next_pushed)
         ? img_white_pushed_contiguous_
         : (is_playing ? img_white_pushed_ : img_white_);
         
         draw_key(i, kKeyPropertyList[i % 12], img);
     }
     
     for(int i = 0; i < kNumKeys; ++i) {
         if(IsBlackKey(i) == false) { continue; }
         
         bool const is_playing = playing_notes_[i];
         
         auto const &img = (is_playing ? img_black_pushed_ : img_black_);
         draw_key(i, kKeyPropertyList[i % 12], img);
     }
     
     auto font = wxFont(wxFontInfo(wxSize(8, 10)).Family(wxFONTFAMILY_DEFAULT));
     dc.SetFont(font);
     for(int i = 0; i < kNumKeys; i += 12) {
         int const octave = i / 12;
         dc.DrawLabel(wxString::Format("C%d", i / 12 - 2),
                      wxBitmap(),
                      wxRect(wxPoint(octave * kKeyWidth * 7 - disp_shift, rect.GetHeight() * 0.8),
                             wxSize(kKeyWidth, 10)),
                      wxALIGN_CENTER
                      );
     }
 }