praat_ExperimentMFC.cpp 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /* praat_ExperimentMFC.cpp
  2. *
  3. * Copyright (C) 2001-2007,2009-2012,2015-2018 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 2 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. #include "praat_ExperimentMFC.h"
  19. // MARK: - CATEGORIES
  20. // MARK: Query
  21. DIRECT (REAL_Categories_getEntropy) {
  22. NUMBER_ONE (Categories)
  23. double result = Categories_getEntropy (me);
  24. NUMBER_ONE_END (U" bits")
  25. }
  26. // MARK: Modify
  27. DIRECT (MODIFY_Categories_sort) {
  28. MODIFY_EACH (Categories)
  29. Categories_sort (me);
  30. MODIFY_EACH_END
  31. }
  32. // MARK: - EXPERIMENT_MFC
  33. DIRECT (WINDOW_ExperimentMFC_run) {
  34. if (theCurrentPraatApplication -> batch) Melder_throw (U"Cannot run experiments from the command line.");
  35. autoRunnerMFC runner;
  36. {// scope
  37. /*
  38. This `scope` comment refers to the idea that an autoThing (here, `list`)
  39. is created in the beginning of the scope and invalidated at the end of the scope (by `move`).
  40. */
  41. FIND_TYPED_LIST (ExperimentMFC, ExperimentMFCList)
  42. Melder_assert (list->size >= 1);
  43. Melder_assert (list->at [1] -> classInfo == classExperimentMFC);
  44. Melder_assert (list->at [list->size] -> classInfo == classExperimentMFC);
  45. runner = RunnerMFC_create (U"listening experiments", list.move());
  46. /*
  47. Now that `list` has been moved, it has become invalid.
  48. We help the compiler notice this by ending the scope here:
  49. */
  50. }
  51. /*
  52. As a result of the scope braces above, the compiler will now protest
  53. if we refer to `list` in the next line. So instead we refer to the `runner`-internal experiments,
  54. which are still in scope and haven't been invalidated:
  55. */
  56. praat_installEditorN (runner.get(), runner -> experiments->asDaataList()); // refer to the moved version!
  57. runner.releaseToUser();
  58. END }
  59. DIRECT (NEW_ExperimentMFC_extractResults) {
  60. CONVERT_EACH (ExperimentMFC)
  61. autoResultsMFC result = ExperimentMFC_extractResults (me);
  62. CONVERT_EACH_END (my name.get())
  63. }
  64. // MARK: - RESULTS_MFC
  65. DIRECT (INTEGER_ResultsMFC_getNumberOfTrials) {
  66. NUMBER_ONE (ResultsMFC)
  67. integer result = my numberOfTrials;
  68. NUMBER_ONE_END (U" trials")
  69. }
  70. FORM (STRING_ResultsMFC_getResponse, U"ResultsMFC: Get response", nullptr) {
  71. NATURAL (trial, U"Trial", U"1")
  72. OK
  73. DO
  74. STRING_ONE (ResultsMFC)
  75. if (trial > my numberOfTrials)
  76. Melder_throw (U"Trial ", trial, U" does not exist (maximum ", my numberOfTrials, U").");
  77. conststring32 result = my result [trial]. response.get();
  78. STRING_ONE_END
  79. }
  80. FORM (STRING_ResultsMFC_getStimulus, U"ResultsMFC: Get stimulus", nullptr) {
  81. NATURAL (trial, U"Trial", U"1")
  82. OK
  83. DO
  84. STRING_ONE (ResultsMFC)
  85. if (trial > my numberOfTrials)
  86. Melder_throw (U"Trial ", trial, U" does not exist (maximum ", my numberOfTrials, U").");
  87. conststring32 result = my result [trial]. stimulus.get();
  88. STRING_ONE_END
  89. }
  90. DIRECT (NEW1_ResultsMFC_removeUnsharedStimuli) {
  91. CONVERT_COUPLE (ResultsMFC)
  92. autoResultsMFC result = ResultsMFC_removeUnsharedStimuli (me, you);
  93. CONVERT_COUPLE_END (your name.get(), U"_shared")
  94. }
  95. DIRECT (NEW_ResultsMFC_to_Categories_stimuli) {
  96. CONVERT_EACH (ResultsMFC)
  97. autoCategories result = ResultsMFC_to_Categories_stimuli (me);
  98. CONVERT_EACH_END (my name.get())
  99. }
  100. DIRECT (NEW_ResultsMFC_to_Categories_responses) {
  101. CONVERT_EACH (ResultsMFC)
  102. autoCategories result = ResultsMFC_to_Categories_responses (me);
  103. CONVERT_EACH_END (my name.get())
  104. }
  105. DIRECT (NEW1_ResultsMFCs_to_Table) {
  106. CONVERT_LIST (ResultsMFC)
  107. autoTable result = ResultsMFCs_to_Table (& list);
  108. CONVERT_LIST_END (U"allResults")
  109. }
  110. // MARK: - buttons
  111. void praat_ExperimentMFC_init () {
  112. Thing_recognizeClassesByName (classExperimentMFC, classResultsMFC, nullptr);
  113. praat_addAction1 (classCategories, 0, U"Sort", nullptr, 0, MODIFY_Categories_sort);
  114. praat_addAction1 (classCategories, 1, U"Get entropy", nullptr, 0, REAL_Categories_getEntropy);
  115. praat_addAction1 (classExperimentMFC, 0, U"Run", nullptr, 0, WINDOW_ExperimentMFC_run);
  116. praat_addAction1 (classExperimentMFC, 0, U"Extract results", nullptr, 0, NEW_ExperimentMFC_extractResults);
  117. praat_addAction1 (classResultsMFC, 0, U"Query -", nullptr, 0, nullptr);
  118. praat_addAction1 (classResultsMFC, 1, U"Get number of trials", nullptr, 1, INTEGER_ResultsMFC_getNumberOfTrials);
  119. praat_addAction1 (classResultsMFC, 1, U"Get stimulus...", nullptr, 1, STRING_ResultsMFC_getStimulus);
  120. praat_addAction1 (classResultsMFC, 1, U"Get response...", nullptr, 1, STRING_ResultsMFC_getResponse);
  121. praat_addAction1 (classResultsMFC, 0, U"Modify", nullptr, 0, nullptr);
  122. praat_addAction1 (classResultsMFC, 2, U"Remove unshared stimuli", 0, 0, NEW1_ResultsMFC_removeUnsharedStimuli);
  123. praat_addAction1 (classResultsMFC, 0, U"Convert", nullptr, 0, nullptr);
  124. praat_addAction1 (classResultsMFC, 0, U"To Categories (stimuli)", nullptr, 0, NEW_ResultsMFC_to_Categories_stimuli);
  125. praat_addAction1 (classResultsMFC, 0, U"To Categories (responses)", nullptr, 0, NEW_ResultsMFC_to_Categories_responses);
  126. praat_addAction1 (classResultsMFC, 0, U"Collect", nullptr, 0, nullptr);
  127. praat_addAction1 (classResultsMFC, 0, U"Collect to Table", nullptr, 0, NEW1_ResultsMFCs_to_Table);
  128. }
  129. /* End of file praat_ExperimentMFC.cpp */