chiark / gitweb /
Merge branch 'arkkra' into shiny
[mup] / mup / mupmate / Run.H
1 /* Copyright (c) 2006 by Arkkra Enterprises */
2 /* All rights reserved */
3
4 #ifndef _RUN_H_
5 #define _RUN_H_
6
7 // Classes for Run menu off of main toolbar
8
9 #include <FL/Fl.H>
10 #include <FL/Fl_Double_Window.H>
11 #include <FL/Fl_Text_Editor.H>
12 #include <FL/Fl_Input.H>
13 #include <FL/Fl_Button.H>
14 #include <FL/Fl_Return_Button.H>
15 #include <FL/Fl_Check_Button.H>
16 #include <FL/Fl_Value_Input.H>
17 #include "globals.H"
18 #include "File.H"
19 #include "Config.H"
20 #include <stdio.h>
21 #include <sys/types.h>
22 #ifdef OS_LIKE_UNIX
23 #include <signal.h>
24 #endif
25 #ifdef OS_LIKE_WIN32
26 #include <windef.h>
27 #include <winbase.h>
28 #include <winnt.h>
29 #include <process.h>
30 #endif
31
32 // Information about a non-waited-for process
33 #ifdef OS_LIKE_WIN32
34 typedef PROCESS_INFORMATION Proc_Info;
35 #else
36 typedef pid_t Proc_Info;
37 #endif
38
39 // We limit the number of macros user can define,
40 // to fit in a reasonably small dialog window.
41 #define MAX_MACROS      5
42
43
44 // Class for asking user what arguments to pass to Mup when running it
45
46 class Run_parameters_dialog : Fl_Double_Window {
47
48 friend class Run;
49
50 public:
51         Run_parameters_dialog(void);
52         ~Run_parameters_dialog(void);
53
54         // Callbacks
55         static void combine_cb(Fl_Widget *, void * data);
56         static void extract_cb(Fl_Widget *, void * data);
57         static void selected_pages_cb(Fl_Widget *, void * data);
58         static void clear_form_cb(Fl_Widget *, void * data);
59         static void Macros_cb(Fl_Widget *, void * data);
60         static void Save_cb(Fl_Widget *, void * data);
61         static void Cancel_cb(Fl_Widget *, void * data);
62
63         // Returns true if macro definition is invalid.
64         static bool macro_error(const char * macro);
65
66 private:
67         // Callbacks
68         void combine(void);
69         void extract(void);
70         void selected_pages(void);
71         void clear_form(void);
72         void Macros(void);
73         void Save(void);
74         void Cancel(void);
75
76         // Widgets
77         Fl_Check_Button * enable_combine_p;
78         Positive_Int_Input * rest_combine_p;
79         Positive_Int_Input * first_page_p;
80         Fl_Group * pages_p;
81           Fl_Check_Button * all_p;
82           Fl_Check_Button * odd_p;
83           Fl_Check_Button * even_p;
84           Fl_Check_Button * selected_p;
85           Fl_Input * page_list_p;
86         Fl_Input * staff_list_p;
87         Int_Input * extract_begin_p;
88         Int_Input * extract_end_p;
89         Fl_Group * macros_group_p;
90           Fl_Input * macro_definitions_p[MAX_MACROS];
91         Fl_Return_Button * save_p;
92         Fl_Button * clear_form_p;
93         Fl_Button * cancel_p;
94
95         // Saved values for run parameters
96         bool saved_enable_combine;
97         char saved_combine_measures[8];
98         char saved_first_page[8];
99         enum { ALL_PAGES, ODD_PAGES, EVEN_PAGES, SELECTED_PAGES } saved_pages;
100         char * saved_page_list;
101         char * saved_staff_list;
102         char saved_extract_begin[8];
103         char saved_extract_end[8];
104         char * saved_macro_definitions[MAX_MACROS];
105 };
106
107
108 // Class for displaying stderr output from Mup to user
109
110 class Error_report : public Fl_Double_Window
111 {
112 public:
113         Error_report(void);
114         ~Error_report(void);
115
116         // Reads the file where stderr was saved
117         int loadfile(const char * filename);
118
119         // Callbacks
120         static void OK_cb(Fl_Widget *, void *);
121         static void font_change_cb(void * data, Fl_Font font, unsigned char size);
122
123 private:
124         // Callbacks
125         void font_change(Fl_Font font, unsigned char size);
126         void OK(void);
127
128         // Widgets
129         Fl_Text_Display * text_p;
130         Font_change_registration * font_change_reg_p;
131         Fl_Return_Button * ok_p;
132 };
133
134
135
136 // Class for the Run menu on the main menu bar
137
138 class Run {
139
140 friend class File;      // For auto-display
141
142 public:
143         Run(void);
144         ~Run(void);
145
146         // To know which file to run Mup on
147         void set_file(File * file);
148         // Kill off child processes
149         void clean_up(void);
150
151         // Callbacks
152         static void Display_cb(Fl_Widget *, void * data);
153         static void Play_cb(Fl_Widget *, void * data);
154         static void WritePostScript_cb(Fl_Widget *, void * data);
155         static void WriteMIDI_cb(Fl_Widget *, void * data);
156         static void Options_cb(Fl_Widget *, void * data);
157
158 private:
159         // Callbacks
160         void Display(void);
161         void Play(void);
162         void WritePostScript(void);
163         void WriteMIDI(void);
164         void Options(void);
165
166         // This runs Mup and maybe viewer/player
167         void Run_Mup(bool midi, bool show_or_play);
168
169         // Execute the command with given argv.
170         // If proc_info_p is zero, wait for the process to complete,
171         // otherwise fill it in with information about the spawned process,
172         // so that the caller can keep track of it while it runs independently.
173         // The hide_window parameter is only used for Windows and causes the
174         // spawned process to be created with flags to not create a window,
175         // This lets us use a console mode version of Mup, so traditional users
176         // can continue to run Mup in a console without mupmate, but we can
177         // run the same .exe without the annoyance of a console popping up.
178         // Returns 0 on success, -1 on failure to create process,
179         // or what the process returned if it had non-zero exit code
180         // and was waited for. If a not-waited-for process returns 0,
181         // proc_info_p will contain handle or pid information.
182         int execute_command(const char **argv, Proc_Info * proc_info_p,
183                                                 bool hide_window = false);
184
185         // kill off a previously spawned child process
186         void kill_process(const Proc_Info * const proc_info_p,
187                                         const char * const description);
188
189         // Report if we have running helper programs
190         bool has_MIDI_child(void);
191         bool has_display_child(void);
192
193 #ifdef OS_LIKE_WIN32
194         // To check if using displayer/player we know how to handle specially
195         static bool is_gsview(const char * command);
196         static bool is_mplayer(const char * command);
197 #endif
198
199         // Widgets
200         Run_parameters_dialog * parameters_p;
201         Error_report * report_p;
202         File * file_p;
203
204         // Handles for child processes
205         Proc_Info display_child;
206         Proc_Info MIDI_child;
207 };
208
209 #endif