OSDN Git Service

[dennco] Implemented the plugin feature.
[dennco/dennco.git] / Source / plugins / SamplePlugin1 / SamplePlugin1 / plugin.cpp
1
2
3 #include "dennco_plugin.h"
4 #include "ui_dialog.h"
5
6 #include <QDialog>
7 #include <QDebug>
8
9
10 class PluginDialog;
11
12 static PluginDialog *s_dialog = NULL;
13
14 class PluginDialog : public QDialog
15 {
16     Ui::Dialog *d_ui;
17
18 public:
19
20     static void construct()
21     {
22         if (!s_dialog)
23         {
24             s_dialog = new PluginDialog;
25         }
26     }
27
28     static PluginDialog* instance()
29     {
30         return s_dialog;
31     }
32
33     static void destruct()
34     {
35         if (s_dialog)
36         {
37             s_dialog->close();
38             s_dialog->deleteLater();
39             s_dialog = NULL;
40         }
41     }
42
43     PluginDialog()
44     {
45         d_ui = new Ui::Dialog;
46         d_ui->setupUi(this);
47     }
48
49     virtual ~PluginDialog()
50     {
51     }
52
53     void setValue1(float v)
54     {
55         d_ui->DenncoToPlugin1->setValue(v*100);
56     }
57
58     void setValue2(float v)
59     {
60         d_ui->DenncoToPlugin2->setValue(v*100);
61     }
62
63     float getValue1() const
64     {
65         return d_ui->PluginToDennco1->value() / 100.0f;
66     }
67
68     float getValue2() const
69     {
70         return d_ui->PluginToDennco2->value() / 100.0f;
71     }
72
73 };
74
75 PLUGINAPI bool init()
76 {
77     PluginDialog::construct();
78     PluginDialog::instance()->show();
79
80     return true;
81 }
82
83 PLUGINAPI bool unload()
84 {
85     PluginDialog::destruct();
86
87     return true;
88 }
89
90 PLUGINAPI float queryPluginValue(const char* name)
91 {
92     if (strcmp("input1", name) == 0)
93     {
94         return PluginDialog::instance()->getValue1();
95     }
96     else if (strcmp("input2", name) == 0)
97     {
98         return PluginDialog::instance()->getValue2();
99     }
100     else
101     {
102         QString msg;
103         msg.sprintf("SamplePlugin1: queryPluginValue: %s not found!\n", name);
104         qDebug() << msg;
105     }
106     return 0.0f;
107 }
108
109 PLUGINAPI void  setValueToPlugin(const char* name, float value)
110 {
111     if (strcmp("output1", name) == 0)
112     {
113         PluginDialog::instance()->setValue1(value);
114     }
115     else if (strcmp("output2", name) == 0)
116     {
117         PluginDialog::instance()->setValue2(value);
118     }
119     else
120     {
121         QString msg;
122         msg.sprintf("SamplePlugin1: setValueToPlugin: %s not found!\n", name);
123         qDebug() << msg;
124     }
125 }