-
Notifications
You must be signed in to change notification settings - Fork 0
/
Constellations.cpp
226 lines (159 loc) · 5.86 KB
/
Constellations.cpp
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
/*
==============================================================================
Constellations.cpp
Created: 25 Mar 2022 12:57:20pm
Author: renda
==============================================================================
*/
#include "Constellations.h"
std::vector<std::string> Constellations::visibleConstellations()
{
Py_Initialize();
PyRun_SimpleString("import pandas as pd");
PyRun_SimpleString("from datetime import date");
PyRun_SimpleString("import time");
PyRun_SimpleString("import requests");
PyRun_SimpleString("import json");
PyRun_SimpleString("from astroquery.mast import Observations");
PyRun_SimpleString("from astropy.coordinates import EarthLocation, AltAz, SkyCoord");
PyRun_SimpleString("import astropy.units as u");
PyRun_SimpleString("from astropy.io import fits");
PyRun_SimpleString("import visible_stars_data");
PyRun_SimpleString("import numpy as np");
PyObject* pyModule = PyImport_ImportModule("get_visible_stars");
if (pyModule != NULL)
{
PyObject* pValue = PyObject_CallMethod(pyModule, "get_stars", NULL);
if (pValue == NULL)
{
//DBG("ERROR");
//exit(ERROR);
std::vector<std::string> vect;
vect = { "Dra", "Crv", "Leo", "Lib",
"Lup", "Lyn", "Lac", "Lyr", "Com", "Cep",
"Boo", "UMa", "CVn", "Sge", "Cen", "Vul", "Sex",
"Oph", "Her", "Ser", "UMi", "Cnc", "CrB", "Cam",
"Crt", "Cas", "Cyg", "Vir", "LMi" };
return vect;
}
else
{
auto result = _PyUnicode_AsString(pValue);
auto result2 = std::string(result);
//DBG(result2);
std::vector<std::string> vect;
std::stringstream ss(result2);
while (ss.good())
{
std::string substr;
std::getline(ss, substr, ',');
vect.push_back(substr);
}
DBG("SUCCESS");
return vect;
}
}
else
{
std::vector<std::string> vect;
vect = { "Dra", "Crv", "Leo", "Lib",
"Lup", "Lyn", "Lac", "Lyr", "Com", "Cep",
"Boo", "UMa", "CVn", "Sge", "Cen", "Vul", "Sex",
"Oph", "Her", "Ser", "UMi", "Cnc", "CrB", "Cam",
"Crt", "Cas", "Cyg", "Vir", "LMi"};
return vect;
}
Py_Finalize();
}
std::vector<int> Constellations::sonification(juce::String star)
{
Py_Initialize();
//PyRun_SimpleString("import sys");
//PyRun_SimpleString("sys.path.append(\"C:\\Users\\renda\\Documents\\provaJuce\\mixerPluginProjectFinale\\Builds\\VisualStudio2022\")");
PyRun_SimpleString("import pandas as pd");
PyRun_SimpleString("import requests");
PyRun_SimpleString("from astroquery.mast import Observations");
PyRun_SimpleString("from astropy.coordinates import SkyCoord");
PyRun_SimpleString("import astropy.units as u");
PyRun_SimpleString("from astropy.io import fits");
PyRun_SimpleString("import visible_stars_data");
PyRun_SimpleString("from astropy import coordinates");
PyRun_SimpleString("import numpy as np");
PyRun_SimpleString("from astropy.io import fits");
PyRun_SimpleString("from sklearn.preprocessing import MinMaxScaler");
//juce::String filePath = juce::File::getCurrentWorkingDirectory().getFullPathName();
//DBG(filePath);
PyObject* pyModule = PyImport_ImportModule("get_visible_stars");
//jassert(pyModule != NULL);
if (pyModule != NULL)
{
auto starString = star.toStdString();
auto starChar = starString.c_str();
PyObject* pValue = PyObject_CallMethod(pyModule, "get_sonification", "s", starChar);
//jassert(pValue != NULL);
if (pValue == NULL)
{
//DBG("ERROR");
//exit(ERROR);
srand(time(0));
int _min = 48;//min
int _max = 120;//max
const int total_numbers = 100;//total numbers you want to generate
int _array[total_numbers] = { 0 };
std::vector<int> intNumbers;
int random_number = -1;
for (int i = 0; i < total_numbers; ++i)
{
random_number = _min + rand() % ((_max - _min) + 1);
_array[i] = random_number;
intNumbers.push_back(_array[i]);
}
return intNumbers;
}
else
{
auto result = _PyUnicode_AsString(pValue);
auto result2 = std::string(result);
std::vector<std::string> vect;
std::stringstream ss(result2);
while (ss.good())
{
std::string substr;
std::getline(ss, substr, ',');
vect.push_back(substr);
}
std::vector<int> intNumbers;
for (int i = 0; i < vect.size(); i++)
{
std::stringstream str(vect[i]);
int x;
str >> x;
if (!str)
{
DBG("CONVERSION ERROR");
}
intNumbers.push_back(x);
}
DBG("SUCCESS");
return intNumbers;
}
}
else
{
srand(time(0));
int _min = 48;//min
int _max = 120;//max
const int total_numbers = 100;//total numbers you want to generate
int _array[total_numbers] = { 0 };
std::vector<int> intNumbers;
int random_number = -1;
for (int i = 0; i < total_numbers; ++i)
{
random_number = _min + rand() % ((_max - _min) + 1);
_array[i] = random_number;
intNumbers.push_back(_array[i]);
}
return intNumbers;
}
Py_Finalize();
}