EEGWindow.cpp 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* EEGWindow.cpp
  2. *
  3. * Copyright (C) 2011-2012,2013,2014,2015,2016,2017 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 "EEGWindow.h"
  19. #include "EditorM.h"
  20. Thing_implement (EEGWindow, TextGridEditor, 0);
  21. #include "prefs_define.h"
  22. #include "EEGWindow_prefs.h"
  23. #include "prefs_install.h"
  24. #include "EEGWindow_prefs.h"
  25. #include "prefs_copyToInstance.h"
  26. #include "EEGWindow_prefs.h"
  27. static void menu_cb_EEGWindowHelp (EEGWindow, EDITOR_ARGS_DIRECT) { Melder_help (U"EEG window"); }
  28. void structEEGWindow :: v_createMenus () {
  29. EEGWindow_Parent :: v_createMenus ();
  30. }
  31. void structEEGWindow :: v_createHelpMenuItems (EditorMenu menu) {
  32. TextGridEditor_Parent :: v_createHelpMenuItems (menu);
  33. EditorMenu_addCommand (menu, U"EEGWindow help", '?', menu_cb_EEGWindowHelp);
  34. }
  35. conststring32 structEEGWindow :: v_getChannelName (integer channelNumber) {
  36. Melder_assert (our eeg != nullptr);
  37. return our eeg -> channelNames [channelNumber].get();
  38. }
  39. static void menu_cb_ExtractSelectedEEG_preserveTimes (EEGWindow me, EDITOR_ARGS_DIRECT) {
  40. if (my endSelection <= my startSelection) Melder_throw (U"No selection.");
  41. autoEEG extract = EEG_extractPart (my eeg, my startSelection, my endSelection, true);
  42. Editor_broadcastPublication (me, extract.move());
  43. }
  44. static void menu_cb_ExtractSelectedEEG_timeFromZero (EEGWindow me, EDITOR_ARGS_DIRECT) {
  45. if (my endSelection <= my startSelection) Melder_throw (U"No selection.");
  46. autoEEG extract = EEG_extractPart (my eeg, my startSelection, my endSelection, false);
  47. Editor_broadcastPublication (me, extract.move());
  48. }
  49. void structEEGWindow :: v_createMenuItems_file_extract (EditorMenu menu) {
  50. EEGWindow_Parent :: v_createMenuItems_file_extract (menu);
  51. our extractSelectedEEGPreserveTimesButton =
  52. EditorMenu_addCommand (menu, U"Extract selected EEG (preserve times)", 0, menu_cb_ExtractSelectedEEG_preserveTimes);
  53. our extractSelectedEEGTimeFromZeroButton =
  54. EditorMenu_addCommand (menu, U"Extract selected EEG (time from zero)", 0, menu_cb_ExtractSelectedEEG_timeFromZero);
  55. }
  56. void structEEGWindow :: v_updateMenuItems_file () {
  57. EEGWindow_Parent :: v_updateMenuItems_file ();
  58. GuiThing_setSensitive (our extractSelectedEEGPreserveTimesButton, our endSelection > our startSelection);
  59. GuiThing_setSensitive (our extractSelectedEEGTimeFromZeroButton, our endSelection > our startSelection);
  60. }
  61. void EEGWindow_init (EEGWindow me, conststring32 title, EEG eeg) {
  62. my eeg = eeg; // before initing, because initing will already draw!
  63. TextGridEditor_init (me, title, eeg -> textgrid.get(), eeg -> sound.get(), false, nullptr, nullptr);
  64. }
  65. autoEEGWindow EEGWindow_create (conststring32 title, EEG eeg) {
  66. try {
  67. autoEEGWindow me = Thing_new (EEGWindow);
  68. EEGWindow_init (me.get(), title, eeg);
  69. return me;
  70. } catch (MelderError) {
  71. Melder_throw (U"EEG window not created.");
  72. }
  73. }
  74. /* End of file EEGWindow.cpp */