aboutsummaryrefslogtreecommitdiff
path: root/composer/Editor.cpp
blob: 1b62b55fdb12ee9989969b7848a61b9ea1c738a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include "Editor.hpp"
#include "Track.hpp"
#include "Song.hpp"

#include <iostream>
#include <string>

#include <m_pd.h>

#include "editor_tk.cpp"
static const int editor_tk_len = sizeof(editor_tk) / sizeof(editor_tk[0]);

using std::cerr;
using std::endl;
using std::string;

static char hexnibble(unsigned int i)
{
    i &= 0xf;
    return (i < 0xa) ? ('0' + i) : ('a' + i - 0xa);
}

static const char* urlencode(char c)
{
    static char buf[4];
    buf[0] = '%';
    buf[1] = hexnibble((c & 0xf0) >> 4);
    buf[2] = hexnibble(c & 0xf);
    buf[3] = '\0';
    return &buf[0];
}

void Editor::uploadCode()
{
    sys_gui("proc Xeval {c {d {}}} {switch $c {begin {set ::Xeval_map {}; for {set i 0} {$i < 256} {incr i} {lappend ::Xeval_map \%[format \%02x $i] [format \%c $i]}; set ::Xeval_data {}} data {append ::Xeval_data [string map $::Xeval_map $d]\\n} end {uplevel #0 $::Xeval_data; unset ::Xeval_map; unset ::Xeval_data}}}\n"); 
    sys_gui("Xeval begin\n");
    for(int i = 0; i < editor_tk_len; i++)
    {
        string s = "Xeval data {";
        string l = editor_tk[i];
        for(int j = 0; j < l.length(); j++)
        {
            if(isalnum(l[j])) s.append(1, l[j]);
            else s += string(urlencode(l[j]));
        }
        s += "}\n";
        sys_gui(const_cast<char*>(s.c_str()));
    }
    sys_gui("Xeval end\n");
}

void Editor::init(t_track_proxy *x)
{
    uploadCode();
    sys_vgui("pd::composer::init %s %s %s %d %s %d\n",
        x->editor_recv->s_name,
        x->track->getSong()->getName().c_str(),
        x->track->getName().c_str(),
        16,
        "NULL",
#ifdef DEBUG
        1
#else
        0
#endif
    );
}

void Editor::dispatch(t_track_proxy *x, int argc, t_atom* argv)
{
    string s = "";
    for(int i = 0; i < argc; i++)
    {
        s += " {";
        char buf[MAXPDSTRING];
        atom_string(&argv[i], buf, MAXPDSTRING);
        s += buf;
        s += "}";
    }
    sys_vgui("pd::composer::dispatch %s%s\n",
        x->editor_recv->s_name,
        s.c_str()
        );
}

void Editor::openWindow(t_track_proxy *x)
{
    x->editor_open = 1;
    sys_vgui("pd::composer::openWindow %s\n", x->editor_recv->s_name);
}

void Editor::closeWindow(t_track_proxy *x)
{
    x->editor_open = 0;
    sys_vgui("pd::composer::closeWindow %s\n", x->editor_recv->s_name);
}