~sspresto10/seq24/myseq24

« back to all changes in this revision

Viewing changes to src/lash.cpp

  • Committer: Ivan Hernandez
  • Date: 2008-05-12 20:33:12 UTC
  • Revision ID: ihernandez@kiusys.com-20080512203312-tbeaz08830kbmpa0
Initial import

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//----------------------------------------------------------------------------
 
2
//
 
3
//  This file is part of seq24.
 
4
//
 
5
//  seq24 is free software; you can redistribute it and/or modify
 
6
//  it under the terms of the GNU General Public License as published by
 
7
//  the Free Software Foundation; either version 2 of the License, or
 
8
//  (at your option) any later version.
 
9
//
 
10
//  seq24 is distributed in the hope that it will be useful,
 
11
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
//  GNU General Public License for more details.
 
14
//
 
15
//  You should have received a copy of the GNU General Public License
 
16
//  along with seq24; if not, write to the Free Software
 
17
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
//
 
19
//-----------------------------------------------------------------------------
 
20
 
 
21
#include <string>
 
22
#include <sigc++/slot.h>
 
23
#include <gtkmm.h>
 
24
#include "config.h"
 
25
#include "lash.h"
 
26
#include "midifile.h"
 
27
 
 
28
 
 
29
lash::lash(int *argc, char ***argv)
 
30
{
 
31
#ifdef LASH_SUPPORT
 
32
    m_client = lash_init(lash_extract_args(argc, argv), PACKAGE_NAME,
 
33
        LASH_Config_File, LASH_PROTOCOL(2, 0));
 
34
    if (m_client == NULL) {
 
35
        fprintf(stderr, "Failed to connect to LASH.  Session management will not occur.\n");
 
36
    } else {
 
37
        lash_event_t* event = lash_event_new_with_type(LASH_Client_Name);
 
38
        lash_event_set_string(event, "Seq24");
 
39
        lash_send_event(m_client, event);
 
40
        printf("[Connected to LASH]\n");
 
41
    }
 
42
#endif // LASH_SUPPORT
 
43
}
 
44
 
 
45
 
 
46
void
 
47
lash::set_alsa_client_id(int id)
 
48
{
 
49
#ifdef LASH_SUPPORT
 
50
        lash_alsa_client_id(m_client, id);
 
51
#endif
 
52
}
 
53
 
 
54
 
 
55
void
 
56
lash::start(perform* perform)
 
57
{
 
58
#ifdef LASH_SUPPORT
 
59
        m_perform = perform;
 
60
 
 
61
    /* Process any LASH events every 250 msec (arbitrarily chosen interval) */
 
62
    Glib::signal_timeout().connect(sigc::mem_fun(*this, &lash::process_events), 250);
 
63
#endif // LASH_SUPPORT
 
64
}
 
65
 
 
66
 
 
67
#ifdef LASH_SUPPORT
 
68
 
 
69
bool
 
70
lash::process_events()
 
71
{
 
72
    lash_event_t  *ev = NULL;
 
73
    //lash_config_t *conf = NULL;
 
74
 
 
75
    // Process events
 
76
    while ((ev = lash_get_event(m_client)) != NULL) {
 
77
        handle_event(ev);
 
78
        lash_event_destroy(ev);
 
79
    }
 
80
 
 
81
    return true;
 
82
}
 
83
 
 
84
 
 
85
void
 
86
lash::handle_event(lash_event_t* ev)
 
87
{
 
88
    LASH_Event_Type type   = lash_event_get_type(ev);
 
89
    const char      *c_str = lash_event_get_string(ev);
 
90
    std::string     str    = (c_str == NULL) ? "" : c_str;
 
91
 
 
92
    if (type == LASH_Save_File) {
 
93
        midifile f(str + "/seq24.mid");
 
94
        f.write(m_perform);
 
95
        lash_send_event(m_client, lash_event_new_with_type(LASH_Save_File));
 
96
    } else if (type == LASH_Restore_File) {
 
97
        midifile f(str + "/seq24.mid");
 
98
        f.parse(m_perform, 0);
 
99
        lash_send_event(m_client, lash_event_new_with_type(LASH_Restore_File));
 
100
    } else if (type == LASH_Quit) {
 
101
        m_client = NULL;
 
102
        Gtk::Main::quit();
 
103
    } else {
 
104
                fprintf(stderr, "Warning:  Unhandled LASH event.\n");
 
105
        }
 
106
}
 
107
 
 
108
 
 
109
void
 
110
lash::handle_config(lash_config_t* conf)
 
111
{
 
112
    const char *key     = NULL;
 
113
    const void *val     = NULL;
 
114
    size_t     val_size = 0;
 
115
 
 
116
    key      = lash_config_get_key(conf);
 
117
    val      = lash_config_get_value(conf);
 
118
    val_size = lash_config_get_value_size(conf);
 
119
}
 
120
 
 
121
 
 
122
#endif // LASH_SUPPORT