Update NTK.
[nondaw.git] / sequencer / src / NSM.C
blobe318fa0d5c58588afc10d51b198bef0590d1f7c3
2 /*******************************************************************************/
3 /* Copyright (C) 2012 Jonathan Moore Liles                                     */
4 /*                                                                             */
5 /* This program is free software; you can redistribute it and/or modify it     */
6 /* under the terms of the GNU General Public License as published by the       */
7 /* Free Software Foundation; either version 2 of the License, or (at your      */
8 /* option) any later version.                                                  */
9 /*                                                                             */
10 /* This program is distributed in the hope that it will be useful, but WITHOUT */
11 /* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or       */
12 /* FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for   */
13 /* more details.                                                               */
14 /*                                                                             */
15 /* You should have received a copy of the GNU General Public License along     */
16 /* with This program; see the file COPYING.  If not,write to the Free Software */
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.  */
18 /*******************************************************************************/
20 #include "NSM.H"
23 #include <stdio.h>
24 #include <sys/stat.h>
25 #include <sys/types.h>
26 #include <unistd.h>
28 #include "common.h"
29 #include "config.h"
30 #include "non.H"
31 #include "jack.H"
32 #include "transport.H"
34 #include "gui/ui.H"
36 #define OSC_INTERVAL 0.2f
38 extern Transport transport;
39 extern char *instance_name;
41 extern NSM_Client *nsm;
43 extern UI *ui;
45 NSM_Client::NSM_Client ( )
47     project_filename = 0;
50 int command_open ( const char *name, const char *display_name, const char *client_id, char **out_msg );
51 int command_save ( char **out_msg );
54 int
55 NSM_Client::command_save ( char **out_msg )
57     if ( transport.rolling )
58     {
59         *out_msg = strdup( "Cannot save while transport is running." );
60         return ERR_NOT_NOW;
61     }
62     else
63     {
64         save_song( nsm->project_filename );
65         return ERR_OK;
66     }
69 int 
70 NSM_Client::command_open ( const char *name, const char *display_name, const char *client_id, char **out_msg )
72     if ( transport.rolling )
73     {
74         *out_msg = strdup( "Cannot open while transport is running." );
75         
76         return ERR_NOT_NOW;
77     }
79     if ( song.dirty() )
80     {
81         *out_msg = strdup( "Song has unsaved changes!" );
83         return ERR_UNSAVED_CHANGES;
84     }
86     if ( instance_name )
87         free( instance_name );
89     instance_name = strdup( client_id );
91     if ( ! midi_is_active() )
92     {
93         setup_jack();
94     }
95     else
96     {
97         midi_all_sound_off();
98         midi_shutdown();
99         setup_jack();
100     }
102     char *new_filename;
103     
104     asprintf( &new_filename, "%s.non", name );
106     struct stat st;
108     if ( 0 == stat( new_filename, &st ) )
109     {
110         if ( ! load_song( new_filename ) )
111         {
112             *out_msg = strdup( "Could not open file" );
113             return ERR_GENERAL;
114         }
115     }
116     else
117     {
118         save_song( new_filename );
119     }
121     if ( nsm->project_filename )
122         free( nsm->project_filename );
123     
124     nsm->project_filename = new_filename;
126     return ERR_OK;
129 void
130 NSM_Client::command_active ( bool b )
132     if ( b )
133     {
134         ui->sm_indicator->value( 1 );
135         ui->sm_indicator->tooltip( session_manager_name() );
136     }
137     else
138     {
139         ui->sm_indicator->tooltip( NULL );
140         ui->sm_indicator->value( 0 );
141     }