Debian Codegraph @

fon/praat_ExperimentMFC.cpp

raw
1 /* praat_ExperimentMFC.cpp
2 *
3 * Copyright (C) 2001-2007,2009-2012,2015-2018,2019,2021,2026 Paul Boersma
4 *
5 * This code 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 3 of the License, or (at
8 * your option) any later version.
9 *
10 * This code is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this work. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 #include "praat_ExperimentMFC.h"
20
21 // MARK: - CATEGORIES
22
23 // MARK: Query
24
25 DIRECT (REAL_Categories_getEntropy) {
26 QUERY_ONE_FOR_REAL (Categories)
27 double result = Categories_getEntropy (me);
28 QUERY_ONE_FOR_REAL_END (U" bits")
29 }
30
31 // MARK: Modify
32
33 DIRECT (MODIFY_Categories_sort) {
34 MODIFY_EACH (Categories)
35 Categories_sort (me);
36 MODIFY_EACH_END
37 }
38
39 // MARK: - EXPERIMENT_MFC
40
41 DIRECT (WINDOW_ExperimentMFC_run) {
42 if (theCurrentPraatApplication -> batch)
43 Melder_throw (U"Cannot run experiments from the command line.");
44 autoRunnerMFC runner;
45 {// scope
46 /*
47 This `scope` comment refers to the idea that an autoThing (here, `list`)
48 is created at the beginning of the scope and invalidated at the end of the scope (by `move`).
49 */
50 FIND_ALL_LISTED (ExperimentMFC, ExperimentMFCList)
51 Melder_assert (list->size >= 1);
52 Melder_assert (list->at [1] -> classInfo == classExperimentMFC);
53 Melder_assert (list->at [list->size] -> classInfo == classExperimentMFC);
54 runner = RunnerMFC_create (U"listening experiments", list.move());
55 /*
56 Now that `list` has been moved, it has become invalid.
57 We help the compiler notice this by ending the scope here:
58 */
59 }
60 /*
61 As a result of the scope braces above, the compiler will now protest
62 if we refer to `list` in the next line. So instead we refer to the `runner`-internal experiments,
63 which are still in scope and haven't been invalidated:
64 */
65 praat_installEditorN (runner.get(), runner -> experiments->asDaataList()); // refer to the moved version!
66 runner.releaseToUser();
67 END_NO_NEW_DATA
68 }
69
70 DIRECT (NEW_ExperimentMFC_extractResults) {
71 CONVERT_EACH_TO_ONE (ExperimentMFC)
72 autoResultsMFC result = ExperimentMFC_extractResults (me);
73 CONVERT_EACH_TO_ONE_END (my name.get())
74 }
75
76 // MARK: - RESULTS_MFC
77
78 DIRECT (INTEGER_ResultsMFC_getNumberOfTrials) {
79 QUERY_ONE_FOR_REAL (ResultsMFC)
80 integer result = my numberOfTrials;
81 QUERY_ONE_FOR_REAL_END (U" trials")
82 }
83
84 FORM (STRING_ResultsMFC_getResponse, U"ResultsMFC: Get response", nullptr) {
85 NATURAL (trial, U"Trial", U"1")
86 OK
87 DO
88 QUERY_ONE_FOR_STRING (ResultsMFC)
89 if (trial > my numberOfTrials)
90 Melder_throw (U"Trial ", trial, U" does not exist (maximum ", my numberOfTrials, U").");
91 conststring32 result = my result [trial]. response.get();
92 QUERY_ONE_FOR_STRING_END
93 }
94
95 FORM (STRING_ResultsMFC_getStimulus, U"ResultsMFC: Get stimulus", nullptr) {
96 NATURAL (trial, U"Trial", U"1")
97 OK
98 DO
99 QUERY_ONE_FOR_STRING (ResultsMFC)
100 if (trial > my numberOfTrials)
101 Melder_throw (U"Trial ", trial, U" does not exist (maximum ", my numberOfTrials, U").");
102 conststring32 result = my result [trial]. stimulus.get();
103 QUERY_ONE_FOR_STRING_END
104 }
105
106 DIRECT (NEW1_ResultsMFC_removeUnsharedStimuli) {
107 CONVERT_TWO_TO_ONE (ResultsMFC)
108 autoResultsMFC result = ResultsMFC_removeUnsharedStimuli (me, you);
109 CONVERT_TWO_TO_ONE_END (your name.get(), U"_shared")
110 }
111
112 DIRECT (NEW_ResultsMFC_to_Categories_stimuli) {
113 CONVERT_EACH_TO_ONE (ResultsMFC)
114 autoCategories result = ResultsMFC_to_Categories_stimuli (me);
115 CONVERT_EACH_TO_ONE_END (my name.get())
116 }
117
118 DIRECT (NEW_ResultsMFC_to_Categories_responses) {
119 CONVERT_EACH_TO_ONE (ResultsMFC)
120 autoCategories result = ResultsMFC_to_Categories_responses (me);
121 CONVERT_EACH_TO_ONE_END (my name.get())
122 }
123
124 DIRECT (NEW1_ResultsMFCs_to_Table) {
125 COMBINE_ALL_TO_ONE (ResultsMFC)
126 autoTable result = ResultsMFCs_to_Table (& list);
127 COMBINE_ALL_TO_ONE_END (U"allResults")
128 }
129
130 // MARK: - buttons
131
132 void praat_ExperimentMFC_init () {
133 Thing_recognizeClassesByName (classExperimentMFC, classResultsMFC);
134
135 praat_addAction1 (classCategories, 0, U"Sort", U"Append category...", 1, MODIFY_Categories_sort);
136 praat_addAction1 (classCategories, 1, U"Get entropy", U"Get fraction different", 1, REAL_Categories_getEntropy);
137
138 praat_addAction1 (classExperimentMFC, 0, U"Run", nullptr, 0, WINDOW_ExperimentMFC_run);
139 praat_addAction1 (classExperimentMFC, 0, U"Extract results", nullptr, 0, NEW_ExperimentMFC_extractResults);
140
141 praat_addAction1 (classResultsMFC, 0, U"Query -", nullptr, 0, nullptr);
142 praat_addAction1 (classResultsMFC, 1, U"Get number of trials", nullptr, 1, INTEGER_ResultsMFC_getNumberOfTrials);
143 praat_addAction1 (classResultsMFC, 1, U"Get stimulus...", nullptr, 1, STRING_ResultsMFC_getStimulus);
144 praat_addAction1 (classResultsMFC, 1, U"Get response...", nullptr, 1, STRING_ResultsMFC_getResponse);
145 praat_addAction1 (classResultsMFC, 0, U"Modify", nullptr, 0, nullptr);
146 praat_addAction1 (classResultsMFC, 2, U"Remove unshared stimuli", 0, 0, NEW1_ResultsMFC_removeUnsharedStimuli);
147 praat_addAction1 (classResultsMFC, 0, U"Convert", nullptr, 0, nullptr);
148 praat_addAction1 (classResultsMFC, 0, U"To Categories (stimuli)", nullptr, 0, NEW_ResultsMFC_to_Categories_stimuli);
149 praat_addAction1 (classResultsMFC, 0, U"To Categories (responses)", nullptr, 0, NEW_ResultsMFC_to_Categories_responses);
150 praat_addAction1 (classResultsMFC, 0, U"Collect", nullptr, 0, nullptr);
151 praat_addAction1 (classResultsMFC, 0, U"Collect to Table", nullptr, 0, NEW1_ResultsMFCs_to_Table);
152 }
153
154 /* End of file praat_ExperimentMFC.cpp */