Exemple #1
0
void ptree::write_key(writable& out, const string& key) const 
{
	if (!m_root) {
		out.write(pid_eof);
	}
	uint64_t pos = key_position(key);
	write_range(out, pos, pos+1);
}
Exemple #2
0
void Fl_MIDIKeyboard::center_keyboard(uchar k) {
    if (k <= _firstkey) {                                   // k is too low
        key_position(_firstkey);
        return;
    }
    int nkeys = int(kbdw() / _key_width) + 1;               // number of visible white keys
    int offset = nkeys / 2;                                 // we shift 1/2 nkeys from k
    if (k > _lastkey || white_keys(k, _lastkey) < nkeys) {  // k is too big
        key_position(_maxbottom);
        return;
    }
    for (int i = 0; i < offset; i++) {
        if (white_keys(k, _lastkey) == nkeys) break;
        if (k == _firstkey) break;
        k--;                                                // shift one white key
        if(is_black(k)) k--;
    }
    key_position(k);
}
Exemple #3
0
int Fl_MIDIKeyboard::handle(int e) {
    int ret = Fl_Scroll::handle(e);
    if (ret && (                                // if the event was a keyboard scrolling ...
        (_type == MKB_HORIZONTAL && Fl::event_inside(&hscrollbar)) ||
        (_type == MKB_VERTICAL &&Fl::event_inside(&scrollbar))))
         return 1;                              // exit

    _callback_status = 0;
    switch(e) {
        case FL_PUSH :
            take_focus();
            if (Fl::event_button1() && (_pressmode & MKB_PRESS_MOUSE))
                press_key(_below_mouse);        // press the key below mouse
            return 1;
        case FL_DRAG :
            if (!Fl::event_inside(this) || Fl::event_inside(&hscrollbar) || Fl::event_inside(&scrollbar)){
                release_key(_below_mouse);      // if the mouse leaved the keyboard, release the key
                _below_mouse = -1;
            }
            else {
                short new_below_mouse = find_key(Fl::event_x(), Fl::event_y());
                if (new_below_mouse != _below_mouse) {  // the key below mouse changed
                    if (_pressmode & MKB_PRESS_MOUSE) {
                        release_key(_below_mouse);
                        press_key(new_below_mouse);
                    }
                    _below_mouse = new_below_mouse;
                }
            }
            if( (_scrollmode & MKB_SCROLL_MOUSE) &&     // scrolling with mouse
                !_autodrag &&
                ( ( _type == MKB_HORIZONTAL && ( Fl::event_inside(x()-20, y(), x(), y()+h()) ||
                                                 Fl::event_inside(x()+w(), y(), x()+w()+20, y()+h()))) ||
                  ( _type == MKB_VERTICAL   && ( Fl::event_inside(x(), y()-20, x()+w(), y()) ||
                                                 Fl::event_inside(x(), y()+h(), x()+w(), y()+h()+20))))
              ) {
                _autodrag = true;
                Fl::add_timeout(0.3, autodrag_to, this);
            }
            return 1;   // idem
        case FL_RELEASE :
            release_key(_below_mouse);
            if (_autodrag) {
                Fl::remove_timeout(autodrag_to, this);
                _autodrag = false;
            }
            return 1;
        case FL_ENTER :
            return 1;
        case FL_MOVE :
            _below_mouse = find_key(Fl::event_x(), Fl::event_y());
            return 1;
        case FL_LEAVE :
            clear_pressed_status();
            _below_mouse = -1;
            return 1;

        case FL_FOCUS :
            if (when() & MKB_WHEN_FOCUS) {
                _callback_status = MKB_FOCUS;
                do_callback();
            }
            return 1;
        case FL_UNFOCUS :
            clear_pressed_status();
            if (when() & MKB_WHEN_FOCUS) {
                _callback_status = MKB_UNFOCUS;
                do_callback();
            }
            return 1;

        case FL_KEYDOWN :
        case FL_KEYUP :
            if ( (_scrollmode & MKB_SCROLL_KEYS) && (e == FL_KEYDOWN) )  {  // handle arrow keys for scrolling
                switch(Fl::event_key()) {
                    case FL_Left :
                        key_position(is_black(_bottomkey-1) ? _bottomkey-2 : _bottomkey-1);
                        if (_below_mouse != -1)     // if mouse is inside the keyboard, recalculate _below_mouse key
                            _below_mouse = find_key(Fl::event_x(), Fl::event_y());
                        return 1;
                    case FL_Right :
                        key_position(is_black(_bottomkey+1) ? _bottomkey+2 : (is_black(_bottomkey+2) ? _bottomkey+3 : _bottomkey+2));
                        if (_below_mouse != -1)    // if mouse is inside the keyboard, recalculate _below_mouse key
                            _below_mouse = find_key(Fl::event_x(), Fl::event_y());
                        return 1;
                    default :
                        break;
                }
            }
            if (_pressmode & MKB_PRESS_KEYS) {      // handle playback with computer keyboard
                uchar offs;                         // is the offset from base C
                switch(Fl::event_key()) {
                    case 'z' :
                        offs = 0;                   // C
                        break;
                    case 's' :
                        offs = 1;                   // C#
                        break;
                    case 'x' :
                        offs = 2;                   // D
                        break;
                    case 'd' :
                        offs = 3;                   // D#
                        break;
                    case 'c' :
                        offs = 4;                   // E
                        break;
                    case 'v' :
                        offs = 5;                   // F
                        break;
                    case 'g' :
                        offs = 6;                   // F#
                        break;
                    case 'b' :
                        offs = 7;                   // G
                        break;
                    case 'h' :
                        offs = 8;                   // G#
                        break;
                    case 'n' :
                        offs = 9;                   // A
                        break;
                    case 'j' :
                        offs = 10;                  // A#
                        break;
                    case 'm' :
                        offs = 11;                  // B
                        break;
                    case ',' :
                        offs = 12;                  // C (upper octave)
                        break;
                    case FL_Up :
                        if (_base_keyinput + 12 < _lastkey && e == FL_KEYDOWN) {
                            _base_keyinput += 12;   // raise one octave
                            center_keyboard(_base_keyinput + 6);
                        }
                        return 1;
                    case FL_Down :
                        if (_base_keyinput - 12 > _firstkey && e == FL_KEYDOWN) {
                            _base_keyinput -= 12;
                            center_keyboard(_base_keyinput + 6);
                        }
                        return 1;                   // lower one octave
                    default :
                        return 0;                   // other keys not recognized
                }
                offs += _base_keyinput;             // get the actual MIDI note number
                if (offs < _firstkey || offs > _lastkey)    // the key is not in the extension
                    return 0;
                if (e == FL_KEYDOWN && !pressed_keys[offs]) {
                    //cout << "handle  Pressed " << (char)offs << "  ";
                    press_key (offs);
                }
                if (e == FL_KEYUP && pressed_keys[offs]) {
                    //cout << "handle  Released " << (char)offs << "  ";
                    release_key(offs);
                }
                return 1;
            }
            break;
        default :
            break;
    }
    return ret;
}