| 1 | /* ArtwordEditor.cpp |
| 2 | * |
| 3 | * Copyright (C) 1992-2013,2015-2024 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 | |
| 19 | #include "ArtwordEditor.h"cxx . . $ `<file>/artsynth/ArtwordEditor.h`/ |
| 20 | #include "machine.h"cxx . . $ `<file>/sys/machine.h`/ |
| 21 | |
| 22 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (ArtwordEditor, Editor, 0); |
| 23 | |
| 24 | static void updateListcxx . . $ updateList(ba38d0641fbc8e84). (ArtwordEditorcxx . . $ ArtwordEditor# me) { |
| 25 | ArtwordDatacxx . . $ ArtwordData# a = & mycxx . . $ `melder/melder.h:44:9`! artwordcxx . . $ structArtwordEditor#artword. -> datacxx . . $ structArtword#data. [(int) mycxx . . $ `melder/melder.h:44:9`! musclecxx . . $ structArtwordEditor#muscle.]; |
| 26 | GuiList_deleteAllItemscxx . . $ GuiList_deleteAllItems(bb293b59cc37ad76). (mycxx . . $ `melder/melder.h:44:9`! listcxx . . $ structArtwordEditor#list.); |
| 27 | for (int16cxx . . $ int16# i = 1; i <= a -> numberOfTargetscxx . . $ structArtwordData#numberOfTargets.; i ++) { |
| 28 | GuiList_insertItemcxx . . $ GuiList_insertItem(896610c612ff86cf). (mycxx . . $ `melder/melder.h:44:9`! listcxx . . $ structArtwordEditor#list., |
| 29 | Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (Melder_singlecxx . . $ Melder_single(f05d861d9dbec9b2). (a -> timescxx . . $ structArtwordData#times. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]), U" ", Melder_singlecxx . . $ Melder_single(f05d861d9dbec9b2). (a -> targetscxx . . $ structArtwordData#targets. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i])), |
| 30 | i |
| 31 | ); |
| 32 | } |
| 33 | Graphics_updateWscxx . . $ Graphics_updateWs(2d838ed765120c5d). (mycxx . . $ `melder/melder.h:44:9`! graphicscxx . . $ structArtwordEditor#graphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 34 | } |
| 35 | |
| 36 | static void gui_button_cb_removeTargetcxx . . $ gui_button_cb_removeTarget(922178d52eea6922). (ArtwordEditorcxx . . $ ArtwordEditor# me, GuiButtonEventcxx . . $ GuiButtonEvent# /* event */) { |
| 37 | autoINTVECcxx . . $ autoINTVEC# selectedPositions = GuiList_getSelectedPositionscxx . . $ GuiList_getSelectedPositions(21bc371a31941fa7). (mycxx . . $ `melder/melder.h:44:9`! listcxx . . $ structArtwordEditor#list.); |
| 38 | for (integercxx . . $ integer# ipos = selectedPositions.sizecxx . . $ autovector#size.; ipos > 0; ipos --) { |
| 39 | integercxx . . $ integer# position = selectedPositions [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ipos]; |
| 40 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (position >= 1 && position <= INT16_MAXcxx . . $ `<external>/3415975807581488833/stdint.h:111:10`!); |
| 41 | Artword_removeTargetcxx . . $ Artword_removeTarget(e6682ef26a6380c3). (mycxx . . $ `melder/melder.h:44:9`! artwordcxx . . $ structArtwordEditor#artword., mycxx . . $ `melder/melder.h:44:9`! musclecxx . . $ structArtwordEditor#muscle., (int16cxx . . $ int16#) position); // guarded conversion |
| 42 | } |
| 43 | updateListcxx . . $ updateList(ba38d0641fbc8e84). (me); |
| 44 | Editor_broadcastDataChangedcxx . . $ Editor_broadcastDataChanged(c0154a85f79216c7). (me); |
| 45 | } |
| 46 | |
| 47 | static void gui_button_cb_addTargetcxx . . $ gui_button_cb_addTarget(922178d52eea6922). (ArtwordEditorcxx . . $ ArtwordEditor# me, GuiButtonEventcxx . . $ GuiButtonEvent# /* event */) { |
| 48 | autostring32cxx . . $ autostring32# timeText = GuiText_getStringcxx . . $ GuiText_getString(9a61f82c13ba8ebc). (mycxx . . $ `melder/melder.h:44:9`! timecxx . . $ structArtwordEditor#time.); |
| 49 | double tim = Melder_atofcxx . . $ Melder_atof(13d725aae188c0cd). (timeText.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 50 | if (isundefcxx . . $ isundef(f8197d536af80c96). (tim)) |
| 51 | tim = 0.0; |
| 52 | autostring32cxx . . $ autostring32# valueText = GuiText_getStringcxx . . $ GuiText_getString(9a61f82c13ba8ebc). (mycxx . . $ `melder/melder.h:44:9`! valuecxx . . $ structArtwordEditor#value.); |
| 53 | const double value = Melder_atofcxx . . $ Melder_atof(13d725aae188c0cd). (valueText.getcxx . . $ _autostring#get(5a2a78a048fb49a8).()); |
| 54 | ArtwordDatacxx . . $ ArtwordData# a = & mycxx . . $ `melder/melder.h:44:9`! artwordcxx . . $ structArtwordEditor#artword. -> datacxx . . $ structArtword#data. [(int) mycxx . . $ `melder/melder.h:44:9`! musclecxx . . $ structArtwordEditor#muscle.]; |
| 55 | int i = 1, oldCount = a -> numberOfTargetscxx . . $ structArtwordData#numberOfTargets.; |
| 56 | Artword_setTargetcxx . . $ Artword_setTarget(d50c23b28181f9b7). (mycxx . . $ `melder/melder.h:44:9`! artwordcxx . . $ structArtwordEditor#artword., mycxx . . $ `melder/melder.h:44:9`! musclecxx . . $ structArtwordEditor#muscle., tim, value); |
| 57 | |
| 58 | /* Optimization instead of "updateList (me)". */ |
| 59 | |
| 60 | Melder_clipcxx . . $ Melder_clip(971c667ea412f82c). (0.0, & tim, mycxx . . $ `melder/melder.h:44:9`! artwordcxx . . $ structArtwordEditor#artword. -> totalTimecxx . . $ structArtword#totalTime.); |
| 61 | while (tim != a -> timescxx . . $ structArtwordData#times. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]) { |
| 62 | i ++; |
| 63 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (i <= a -> numberOfTargets); // can fail if tim is in an extended precision register |
| 64 | } |
| 65 | const conststring32cxx . . $ conststring32# itemText = Melder_catcxx . . $ Melder_cat(7fbf27f4d367f442). (Melder_singlecxx . . $ Melder_single(f05d861d9dbec9b2). (tim), U" ", Melder_singlecxx . . $ Melder_single(f05d861d9dbec9b2). (value)); |
| 66 | if (a -> numberOfTargetscxx . . $ structArtwordData#numberOfTargets. == oldCount) |
| 67 | GuiList_replaceItemcxx . . $ GuiList_replaceItem(896610c612ff86cf). (mycxx . . $ `melder/melder.h:44:9`! listcxx . . $ structArtwordEditor#list., itemText, i); |
| 68 | else |
| 69 | GuiList_insertItemcxx . . $ GuiList_insertItem(896610c612ff86cf). (mycxx . . $ `melder/melder.h:44:9`! listcxx . . $ structArtwordEditor#list., itemText, i); |
| 70 | Graphics_updateWscxx . . $ Graphics_updateWs(2d838ed765120c5d). (mycxx . . $ `melder/melder.h:44:9`! graphicscxx . . $ structArtwordEditor#graphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 71 | Editor_broadcastDataChangedcxx . . $ Editor_broadcastDataChanged(c0154a85f79216c7). (me); |
| 72 | } |
| 73 | |
| 74 | static void gui_radiobutton_cb_togglecxx . . $ gui_radiobutton_cb_toggle(2c9c5093b8e4216a). (ArtwordEditorcxx . . $ ArtwordEditor# me, GuiRadioButtonEventcxx . . $ GuiRadioButtonEvent# event) { |
| 75 | mycxx . . $ `melder/melder.h:44:9`! musclecxx . . $ structArtwordEditor#muscle. = (kArt_musclecxx . . $ kArt_muscle#) event -> positioncxx . . $ structGuiRadioButtonEvent#position.; |
| 76 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! ((int) mycxx . . $ `melder/melder.h:44:9`! muscle > 0); |
| 77 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (mycxx . . $ `melder/melder.h:44:9`! muscle <= kArt_muscle::MAX); |
| 78 | updateListcxx . . $ updateList(ba38d0641fbc8e84). (me); |
| 79 | } |
| 80 | |
| 81 | static void gui_drawingarea_cb_exposecxx . . $ gui_drawingarea_cb_expose(e62f4b1601c27a3f). (ArtwordEditorcxx . . $ ArtwordEditor# me, GuiDrawingArea_ExposeEventcxx . . $ GuiDrawingArea_ExposeEvent# /* event */) { |
| 82 | if (! mycxx . . $ `melder/melder.h:44:9`! graphicscxx . . $ structArtwordEditor#graphics.) |
| 83 | return; |
| 84 | Graphics_clearWscxx . . $ Graphics_clearWs(2d838ed765120c5d). (mycxx . . $ `melder/melder.h:44:9`! graphicscxx . . $ structArtwordEditor#graphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 85 | Artword_drawcxx . . $ Artword_draw(9c5678ce18b5456e). (mycxx . . $ `melder/melder.h:44:9`! artwordcxx . . $ structArtwordEditor#artword., mycxx . . $ `melder/melder.h:44:9`! graphicscxx . . $ structArtwordEditor#graphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), mycxx . . $ `melder/melder.h:44:9`! musclecxx . . $ structArtwordEditor#muscle., true); |
| 86 | } |
| 87 | |
| 88 | static void gui_drawingarea_cb_mousecxx . . $ gui_drawingarea_cb_mouse(fd22905082b7bc5d). (ArtwordEditorcxx . . $ ArtwordEditor# me, GuiDrawingArea_MouseEventcxx . . $ GuiDrawingArea_MouseEvent# event) { |
| 89 | if (! mycxx . . $ `melder/melder.h:44:9`! graphicscxx . . $ structArtwordEditor#graphics.) |
| 90 | return; |
| 91 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (mycxx . . $ `melder/melder.h:44:9`! graphicscxx . . $ structArtwordEditor#graphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 0, mycxx . . $ `melder/melder.h:44:9`! artwordcxx . . $ structArtwordEditor#artword. -> totalTimecxx . . $ structArtword#totalTime., -1.0, 1.0); |
| 92 | Graphics_setInnercxx . . $ Graphics_setInner(2d838ed765120c5d). (mycxx . . $ `melder/melder.h:44:9`! graphicscxx . . $ structArtwordEditor#graphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 93 | double xWC, yWC; |
| 94 | Graphics_DCtoWCcxx . . $ Graphics_DCtoWC(cb6c8e8090c77494). (mycxx . . $ `melder/melder.h:44:9`! graphicscxx . . $ structArtwordEditor#graphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), event -> xcxx . . $ structGuiDrawingArea_MouseEvent#x., event -> ycxx . . $ structGuiDrawingArea_MouseEvent#y., & xWC, & yWC); |
| 95 | Graphics_unsetInnercxx . . $ Graphics_unsetInner(2d838ed765120c5d). (mycxx . . $ `melder/melder.h:44:9`! graphicscxx . . $ structArtwordEditor#graphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 96 | GuiText_setStringcxx . . $ GuiText_setString(d44acbd60ea2b9be). (mycxx . . $ `melder/melder.h:44:9`! timecxx . . $ structArtwordEditor#time., Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (xWC, 6)); |
| 97 | GuiText_setStringcxx . . $ GuiText_setString(d44acbd60ea2b9be). (mycxx . . $ `melder/melder.h:44:9`! valuecxx . . $ structArtwordEditor#value., Melder_fixedcxx . . $ Melder_fixed(5b9062840a6ade99). (yWC, 6)); |
| 98 | } |
| 99 | |
| 100 | void structArtwordEditorcxx . . $ structArtwordEditor# :: v1_dataChangedcxx . . $ structArtwordEditor#v1_dataChanged(c0154a85f79216c7). (Editorcxx . . $ Editor# /* sender */) { |
| 101 | updateListcxx . . $ updateList(ba38d0641fbc8e84). (this); |
| 102 | Graphics_updateWscxx . . $ Graphics_updateWs(2d838ed765120c5d). (graphicscxx . . $ structArtwordEditor#graphics..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 103 | } |
| 104 | |
| 105 | void structArtwordEditorcxx . . $ structArtwordEditor# :: v_createChildrencxx . . $ structArtwordEditor#v_createChildren(49f6e7a06ebc5aa8). () { |
| 106 | int dy = Machine_getMenuBarBottomcxx . . $ Machine_getMenuBarBottom(b126dc7c1de90089). (); |
| 107 | GuiLabel_createShowncxx . . $ GuiLabel_createShown(39026c9008a6a07). (ourcxx . . $ `melder/melder.h:42:9`! windowFormcxx . . $ structEditor#windowForm., 40, 100, dy + 3, dy + 3 + Gui_LABEL_HEIGHTcxx . . $ `sys/Gui.h:97:9`!, U"Targets:", 0); |
| 108 | GuiLabel_createShowncxx . . $ GuiLabel_createShown(39026c9008a6a07). (ourcxx . . $ `melder/melder.h:42:9`! windowFormcxx . . $ structEditor#windowForm., 5, 65, dy + 20, dy + 20 + Gui_LABEL_HEIGHTcxx . . $ `sys/Gui.h:97:9`!, U"Times:", 0); |
| 109 | GuiLabel_createShowncxx . . $ GuiLabel_createShown(39026c9008a6a07). (ourcxx . . $ `melder/melder.h:42:9`! windowFormcxx . . $ structEditor#windowForm., 80, 140, dy + 20, dy + 20 + Gui_LABEL_HEIGHTcxx . . $ `sys/Gui.h:97:9`!, U"Values:", 0); |
| 110 | ourcxx . . $ `melder/melder.h:42:9`! listcxx . . $ structArtwordEditor#list. = GuiList_createShowncxx . . $ GuiList_createShown(88aee17cb4a88a62). (ourcxx . . $ `melder/melder.h:42:9`! windowFormcxx . . $ structEditor#windowForm., 0, 140, dy + 40, dy + 340, true, nullptr); |
| 111 | |
| 112 | GuiButton_createShowncxx . . $ GuiButton_createShown(653ed9987c16d9c1). (ourcxx . . $ `melder/melder.h:42:9`! windowFormcxx . . $ structEditor#windowForm., 10, 130, dy + 410, dy + 410 + Gui_PUSHBUTTON_HEIGHTcxx . . $ `sys/Gui.h:103:9`!, U"Remove target", gui_button_cb_removeTargetcxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97)., this, 0); |
| 113 | |
| 114 | ourcxx . . $ `melder/melder.h:42:9`! drawingAreacxx . . $ structArtwordEditor#drawingArea. = GuiDrawingArea_createShowncxx . . $ GuiDrawingArea_createShown(5a210e61ba6a237d). (ourcxx . . $ `melder/melder.h:42:9`! windowFormcxx . . $ structEditor#windowForm., 170, 470, dy + 10, dy + 310, |
| 115 | gui_drawingarea_cb_exposecxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97)., gui_drawingarea_cb_mousecxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97)., |
| 116 | nullptrcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112)., nullptrcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112)., nullptrcxx . . $ MelderCallback#MelderCallback(fc624d2cd197112)., this, 0 |
| 117 | ); |
| 118 | |
| 119 | GuiLabel_createShowncxx . . $ GuiLabel_createShown(39026c9008a6a07). (ourcxx . . $ `melder/melder.h:42:9`! windowFormcxx . . $ structEditor#windowForm., 220, 270, dy + 340, dy + 340 + Gui_LABEL_HEIGHTcxx . . $ `sys/Gui.h:97:9`!, U"Time:", 0); |
| 120 | ourcxx . . $ `melder/melder.h:42:9`! timecxx . . $ structArtwordEditor#time. = GuiText_createShowncxx . . $ GuiText_createShown(8bcb1f2be7fc31ee). (ourcxx . . $ `melder/melder.h:42:9`! windowFormcxx . . $ structEditor#windowForm., 270, 370, dy + 340, dy + 340 + Gui_TEXTFIELD_HEIGHTcxx . . $ `sys/Gui.h:96:9`!, 0); |
| 121 | |
| 122 | GuiLabel_createShowncxx . . $ GuiLabel_createShown(39026c9008a6a07). (ourcxx . . $ `melder/melder.h:42:9`! windowFormcxx . . $ structEditor#windowForm., 220, 270, dy + 370, dy + 370 + Gui_LABEL_HEIGHTcxx . . $ `sys/Gui.h:97:9`!, U"Value:", 0); |
| 123 | ourcxx . . $ `melder/melder.h:42:9`! valuecxx . . $ structArtwordEditor#value. = GuiText_createShowncxx . . $ GuiText_createShown(8bcb1f2be7fc31ee). (ourcxx . . $ `melder/melder.h:42:9`! windowFormcxx . . $ structEditor#windowForm., 270, 370, dy + 370, dy + 370 + Gui_TEXTFIELD_HEIGHTcxx . . $ `sys/Gui.h:96:9`!, 0); |
| 124 | |
| 125 | GuiButton_createShowncxx . . $ GuiButton_createShown(653ed9987c16d9c1). (ourcxx . . $ `melder/melder.h:42:9`! windowFormcxx . . $ structEditor#windowForm., 240, 360, dy + 410, dy + 410 + Gui_PUSHBUTTON_HEIGHTcxx . . $ `sys/Gui.h:103:9`!, U"Add target", gui_button_cb_addTargetcxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97)., this, GuiButton_DEFAULTcxx . . $ `sys/Gui.h:467:9`!); |
| 126 | |
| 127 | dy = Machine_getMenuBarBottomcxx . . $ Machine_getMenuBarBottom(b126dc7c1de90089). (); |
| 128 | GuiRadioGroup_begincxx . . $ GuiRadioGroup_begin(49f6e7a06ebc5aa8). (); |
| 129 | for (int i = 1; i <= (int) kArt_musclecxx . . $ kArt_muscle#::MAXcxx . . $ kArt_muscle#MAX.; i ++) { |
| 130 | buttoncxx . . $ structArtwordEditor#button. [i] = GuiRadioButton_createShowncxx . . $ GuiRadioButton_createShown(6b1e2d4d89108d7e). (ourcxx . . $ `melder/melder.h:42:9`! windowFormcxx . . $ structEditor#windowForm., |
| 131 | 480, 0, dy, dy + Gui_RADIOBUTTON_HEIGHTcxx . . $ `sys/Gui.h:98:9`!, |
| 132 | kArt_muscle_getTextcxx . . $ kArt_muscle_getText(43a9f12c03e634c9). ((kArt_musclecxx . . $ kArt_muscle#) i), gui_radiobutton_cb_togglecxx . . $ MelderCallback#MelderCallback(aaa169a015c1cf97)., this, 0 |
| 133 | ); |
| 134 | dy += Gui_RADIOBUTTON_HEIGHTcxx . . $ `sys/Gui.h:98:9`! + Gui_RADIOBUTTON_SPACINGcxx . . $ `sys/Gui.h:99:9`! - 2; |
| 135 | } |
| 136 | GuiRadioGroup_endcxx . . $ GuiRadioGroup_end(49f6e7a06ebc5aa8). (); |
| 137 | musclecxx . . $ structArtwordEditor#muscle. = (kArt_musclecxx . . $ kArt_muscle#) 1; |
| 138 | GuiRadioButton_setcxx . . $ GuiRadioButton_set(669e3d212ae3e4fb). (buttoncxx . . $ structArtwordEditor#button. [(int) musclecxx . . $ structArtwordEditor#muscle.]); |
| 139 | } |
| 140 | |
| 141 | autoArtwordEditorcxx . . $ autoArtwordEditor# ArtwordEditor_createcxx . . $ ArtwordEditor_create(d67b063a67fe14e0). (conststring32cxx . . $ conststring32# title, Artwordcxx . . $ Artword# artword) { |
| 142 | try { |
| 143 | autoArtwordEditorcxx . . $ autoArtwordEditor# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (ArtwordEditor); |
| 144 | mycxx . . $ `melder/melder.h:44:9`! artwordcxx . . $ structArtwordEditor#artword. = artword; |
| 145 | Editor_initcxx . . $ Editor_init(13f379e38ac41ed6). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 20, 40, 650, 600, title, artword); |
| 146 | //XtUnmanageChild (my menuBar); |
| 147 | mycxx . . $ `melder/melder.h:44:9`! graphicscxx . . $ structArtwordEditor#graphics. =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). Graphics_create_xmdrawingareacxx . . $ Graphics_create_xmdrawingarea(51b1c75797a7dddf). (mycxx . . $ `melder/melder.h:44:9`! drawingAreacxx . . $ structArtwordEditor#drawingArea.); |
| 148 | updateListcxx . . $ updateList(ba38d0641fbc8e84). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).()); |
| 149 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 150 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 151 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Artword window not created."); |
| 152 | } |
| 153 | } |
| 154 | |
| 155 | /* End of file ArtwordEditor.cpp */ |