1use super::super::meta::py_like_apis::dict_like_api::{DictLikeAPI, DictLikeIter};
2use super::super::meta::py_like_apis::list_like_api::{ListLikeAPI, ListLikeIter};
3use super::super::timesets::*;
4use indexmap::map::IndexMap;
5use pyo3::types::PyAny;
6
7#[macro_export]
8macro_rules! pytimeset_container {
9 ($py:expr, $model_id:expr) => {
10 Py::new(
11 $py,
12 TimesetContainer {
13 model_id: $model_id,
14 },
15 )
16 .unwrap()
17 };
18}
19
20#[pyclass]
21pub struct TimesetContainer {
22 pub model_id: usize,
23}
24
25#[pymethods]
26impl TimesetContainer {
27 fn keys(&self) -> PyResult<Vec<String>> {
28 DictLikeAPI::keys(self)
29 }
30
31 fn values(&self) -> PyResult<Vec<PyObject>> {
32 DictLikeAPI::values(self)
33 }
34
35 fn items(&self) -> PyResult<Vec<(String, PyObject)>> {
36 DictLikeAPI::items(self)
37 }
38
39 fn get(&self, name: &str) -> PyResult<PyObject> {
40 DictLikeAPI::get(self, name)
41 }
42
43 fn __getitem__(&self, name: &str) -> PyResult<PyObject> {
44 DictLikeAPI::__getitem__(self, name)
45 }
46
47 fn __len__(&self) -> PyResult<usize> {
48 DictLikeAPI::__len__(self)
49 }
50
51 fn __iter__(slf: PyRefMut<Self>) -> PyResult<DictLikeIter> {
52 DictLikeAPI::__iter__(&*slf)
53 }
54}
55
56impl DictLikeAPI for TimesetContainer {
57 fn lookup_key(&self) -> &str {
58 &"timesets"
59 }
60
61 fn lookup_table(
62 &self,
63 dut: &std::sync::MutexGuard<origen::core::dut::Dut>,
64 ) -> IndexMap<String, usize> {
65 dut.get_model(self.model_id).unwrap().timesets.clone()
66 }
67
68 fn model_id(&self) -> usize {
69 self.model_id
70 }
71
72 fn new_pyitem(&self, py: Python, name: &str, model_id: usize) -> PyResult<PyObject> {
73 Ok(Py::new(py, super::timeset::Timeset::new(name, model_id))
74 .unwrap()
75 .to_object(py))
76 }
77}
78
79#[macro_export]
80macro_rules! pywavetable_container {
81 ($py:expr, $model_id:expr, $timeset_id:expr, $timeset_name:expr) => {
82 Py::new(
83 $py,
84 WavetableContainer {
85 model_id: $model_id,
86 timeset_id: $timeset_id,
87 timeset_name: String::from($timeset_name),
88 },
89 )
90 .unwrap()
91 };
92}
93
94#[pyclass]
96pub struct WavetableContainer {
97 pub model_id: usize,
98 pub timeset_id: usize,
99 pub timeset_name: String,
100}
101
102#[pymethods]
103impl WavetableContainer {
104 fn keys(&self) -> PyResult<Vec<String>> {
105 DictLikeAPI::keys(self)
106 }
107
108 fn values(&self) -> PyResult<Vec<PyObject>> {
109 DictLikeAPI::values(self)
110 }
111
112 fn items(&self) -> PyResult<Vec<(String, PyObject)>> {
113 DictLikeAPI::items(self)
114 }
115
116 fn get(&self, name: &str) -> PyResult<PyObject> {
117 DictLikeAPI::get(self, name)
118 }
119
120 fn __getitem__(&self, name: &str) -> PyResult<PyObject> {
121 DictLikeAPI::__getitem__(self, name)
122 }
123
124 fn __len__(&self) -> PyResult<usize> {
125 DictLikeAPI::__len__(self)
126 }
127
128 fn __iter__(slf: PyRefMut<Self>) -> PyResult<DictLikeIter> {
129 DictLikeAPI::__iter__(&*slf)
130 }
131}
132
133impl DictLikeAPI for WavetableContainer {
134 fn lookup_key(&self) -> &str {
135 &"wavetables"
136 }
137
138 fn lookup_table(
139 &self,
140 dut: &std::sync::MutexGuard<origen::core::dut::Dut>,
141 ) -> IndexMap<String, usize> {
142 dut.timesets[self.timeset_id].wavetable_ids.clone()
143 }
144
145 fn model_id(&self) -> usize {
146 self.model_id
147 }
148
149 fn new_pyitem(&self, py: Python, name: &str, model_id: usize) -> PyResult<PyObject> {
150 Ok(Py::new(
151 py,
152 super::timeset::Wavetable::new(model_id, self.timeset_id, name),
153 )
154 .unwrap()
155 .to_object(py))
156 }
157}
158
159#[macro_export]
160macro_rules! pywave_group_container {
161 ($py:expr, $model_id:expr, $timeset_id:expr, $wavetable_id:expr, $name:expr) => {
162 Py::new(
163 $py,
164 WaveGroupContainer {
165 model_id: $model_id,
166 timeset_id: $timeset_id,
167 wavetable_id: $wavetable_id,
168 name: String::from($name),
169 },
170 )
171 .unwrap()
172 };
173}
174
175#[pyclass]
177pub struct WaveGroupContainer {
178 pub model_id: usize,
179 pub timeset_id: usize,
180 pub wavetable_id: usize,
181 pub name: String,
182}
183
184#[pymethods]
185impl WaveGroupContainer {
186 fn keys(&self) -> PyResult<Vec<String>> {
187 DictLikeAPI::keys(self)
188 }
189
190 fn values(&self) -> PyResult<Vec<PyObject>> {
191 DictLikeAPI::values(self)
192 }
193
194 fn items(&self) -> PyResult<Vec<(String, PyObject)>> {
195 DictLikeAPI::items(self)
196 }
197
198 fn get(&self, name: &str) -> PyResult<PyObject> {
199 DictLikeAPI::get(self, name)
200 }
201
202 fn __getitem__(&self, name: &str) -> PyResult<PyObject> {
203 DictLikeAPI::__getitem__(self, name)
204 }
205
206 fn __len__(&self) -> PyResult<usize> {
207 DictLikeAPI::__len__(self)
208 }
209
210 fn __iter__(slf: PyRefMut<Self>) -> PyResult<DictLikeIter> {
211 DictLikeAPI::__iter__(&*slf)
212 }
213}
214
215impl DictLikeAPI for WaveGroupContainer {
216 fn lookup_key(&self) -> &str {
217 &"wave_groups"
218 }
219
220 fn lookup_table(
221 &self,
222 dut: &std::sync::MutexGuard<origen::core::dut::Dut>,
223 ) -> IndexMap<String, usize> {
224 dut.wavetables[self.wavetable_id].wave_group_ids.clone()
225 }
226
227 fn model_id(&self) -> usize {
228 self.model_id
229 }
230
231 fn new_pyitem(&self, py: Python, name: &str, model_id: usize) -> PyResult<PyObject> {
232 Ok(Py::new(
233 py,
234 super::timeset::WaveGroup::new(model_id, self.timeset_id, self.wavetable_id, name),
235 )
236 .unwrap()
237 .to_object(py))
238 }
239}
240
241#[macro_export]
242macro_rules! pywave_container {
243 ($py:expr, $model_id:expr, $timeset_id:expr, $wavetable_id:expr, $wave_group_id:expr, $name:expr) => {
244 Py::new(
245 $py,
246 WaveContainer {
247 model_id: $model_id,
248 timeset_id: $timeset_id,
249 wavetable_id: $wavetable_id,
250 wave_group_id: $wave_group_id,
251 name: String::from($name),
252 },
253 )
254 .unwrap()
255 };
256}
257
258#[pyclass]
260pub struct WaveContainer {
261 pub model_id: usize,
262 pub timeset_id: usize,
263 pub wavetable_id: usize,
264 pub wave_group_id: usize,
265 pub name: String,
266}
267
268#[pymethods]
269impl WaveContainer {
270 fn keys(&self) -> PyResult<Vec<String>> {
271 DictLikeAPI::keys(self)
272 }
273
274 fn values(&self) -> PyResult<Vec<PyObject>> {
275 DictLikeAPI::values(self)
276 }
277
278 fn items(&self) -> PyResult<Vec<(String, PyObject)>> {
279 DictLikeAPI::items(self)
280 }
281
282 fn get(&self, name: &str) -> PyResult<PyObject> {
283 DictLikeAPI::get(self, name)
284 }
285
286 fn __getitem__(&self, name: &str) -> PyResult<PyObject> {
287 DictLikeAPI::__getitem__(self, name)
288 }
289
290 fn __len__(&self) -> PyResult<usize> {
291 DictLikeAPI::__len__(self)
292 }
293
294 fn __iter__(slf: PyRefMut<Self>) -> PyResult<DictLikeIter> {
295 DictLikeAPI::__iter__(&*slf)
296 }
297}
298
299impl DictLikeAPI for WaveContainer {
300 fn lookup_key(&self) -> &str {
301 &"waves"
302 }
303
304 fn lookup_table(
305 &self,
306 dut: &std::sync::MutexGuard<origen::core::dut::Dut>,
307 ) -> IndexMap<String, usize> {
308 dut.wave_groups[self.wave_group_id].wave_ids.clone()
309 }
310
311 fn model_id(&self) -> usize {
312 self.model_id
313 }
314
315 fn new_pyitem(&self, py: Python, name: &str, model_id: usize) -> PyResult<PyObject> {
316 Ok(Py::new(
317 py,
318 super::timeset::Wave::new(
319 model_id,
320 self.timeset_id,
321 self.wavetable_id,
322 self.wave_group_id,
323 name,
324 ),
325 )
326 .unwrap()
327 .to_object(py))
328 }
329}
330
331#[macro_export]
332macro_rules! pyevent_container {
333 ($py:expr, $model_id:expr, $timeset_id:expr, $wavetable_id:expr, $wave_group_id:expr, $wave_id:expr, $wave_name:expr) => {
334 Py::new(
335 $py,
336 EventContainer {
337 model_id: $model_id,
338 timeset_id: $timeset_id,
339 wavetable_id: $wavetable_id,
340 wave_group_id: $wave_group_id,
341 wave_id: $wave_id,
342 wave_name: String::from($wave_name),
343 },
344 )
345 .unwrap()
346 };
347}
348
349#[pyclass]
351#[derive(Clone)]
352pub struct EventContainer {
353 pub model_id: usize,
354 pub timeset_id: usize,
355 pub wavetable_id: usize,
356 pub wave_group_id: usize,
357 pub wave_id: usize,
358 pub wave_name: String,
359}
360
361#[pymethods]
362impl EventContainer {
363 fn __getitem__(&self, idx: &PyAny) -> PyResult<PyObject> {
364 ListLikeAPI::__getitem__(self, idx)
365 }
366
367 fn __len__(&self) -> PyResult<usize> {
368 ListLikeAPI::__len__(self)
369 }
370
371 fn __iter__(slf: PyRefMut<Self>) -> PyResult<ListLikeIter> {
372 ListLikeAPI::__iter__(&*slf)
373 }
374}
375
376impl ListLikeAPI for EventContainer {
377 fn item_ids(&self, dut: &std::sync::MutexGuard<origen::core::dut::Dut>) -> Vec<usize> {
378 dut.waves[self.wave_id].events.clone()
379 }
380
381 fn new_pyitem(&self, py: Python, idx: usize) -> PyResult<PyObject> {
382 Ok(Py::new(
383 py,
384 super::timeset::Event::new(
385 self.model_id,
386 self.timeset_id,
387 self.wavetable_id,
388 self.wave_group_id,
389 self.wave_id,
390 &self.wave_name,
391 idx,
392 ),
393 )
394 .unwrap()
395 .to_object(py))
396 }
397
398 fn __iter__(&self) -> PyResult<ListLikeIter> {
399 Ok(ListLikeIter {
400 parent: Box::new((*self).clone()),
401 i: 0,
402 })
403 }
404}