Open Ephys GUI
 All Classes Functions Variables Pages
RecordNode.h
1 /*
2  ------------------------------------------------------------------
3 
4  This file is part of the Open Ephys GUI
5  Copyright (C) 2012 Open Ephys
6 
7  ------------------------------------------------------------------
8 
9  This program is free software: you can redistribute it and/or modify
10  it under the terms of the GNU General Public License as published by
11  the Free Software Foundation, either version 3 of the License, or
12  (at your option) any later version.
13 
14  This program is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  GNU General Public License for more details.
18 
19  You should have received a copy of the GNU General Public License
20  along with this program. If not, see <http://www.gnu.org/licenses/>.
21 
22 */
23 
24 #ifndef __RECORDNODE_H_FB9B1CA7__
25 #define __RECORDNODE_H_FB9B1CA7__
26 
27 
28 #include "../../JuceLibraryCode/JuceHeader.h"
29 #include <stdio.h>
30 #include <map>
31 
32 #include "GenericProcessor.h"
33 
34 /**
35 
36  Receives inputs from all processors that want to save their data.
37  Writes data to disk using fwrite.
38 
39  Receives a signal from the ControlPanel to begin recording.
40 
41  @see GenericProcessor, ControlPanel
42 
43 */
44 
46  public FilenameComponentListener
47 {
48 public:
49 
50  RecordNode();
51  ~RecordNode();
52 
53  void process(AudioSampleBuffer &buffer, MidiBuffer &eventBuffer, int& nSamples);
54 
55  void setParameter (int parameterIndex, float newValue);
56 
57  void addInputChannel(GenericProcessor* sourceNode, int chan);
58 
59  bool enable();
60  bool disable();
61 
62  /** Called by the ControlPanel to determine the amount of space
63  left in the current dataDirectory.
64  */
65  float getFreeSpace();
66 
67  void setChannel(int id, int chan);
68 
69  void setChannelStatus(int chan, bool status);
70 
71  void resetConnections();
72 
73  bool isAudioOrRecordNode() {return true;}
74 
75  void filenameComponentChanged(FilenameComponent*);
76 
77  void createNewDirectory();
78 
79 private:
80 
81  /** Keep the RecordNode informed of acquisition and record states.
82  */
83  bool isRecording, isProcessing, signalFilesShouldClose;
84 
85  /** User-selectable directory for saving data files. Currently
86  defaults to the user's home directory.
87  */
89 
90  /** Automatically generated folder for each recording session.
91  */
92  File rootFolder;
93 
94  /** Determines whether a new rootFolder is created when recording
95  begins.
96  */
98 
99  /** Holds data that has been converted from float to int16 before
100  saving.
101  */
103 
104  /** Integer timestamp saved for each buffer.
105  */
106  int64 timestamp;
107 
108  /** Used to generate timestamps if none are given.
109  */
110  Time timer;
111 
112  /** Holds information for a given channel to be recorded to
113  its own file.
114  */
115  struct Channel
116  {
117  int nodeId;
118  int chan;
119  String name;
120  bool isRecording;
121  String filename;
122  FILE* file;
123  };
124 
125  void closeAllFiles();
126 
127  /** Map of continuous channels.
128  */
129  std::map<int, Channel> continuousChannels;
130 
131  /** Map of event channels.
132  */
133  std::map<int, std::map<int,Channel> > eventChannels;
134 
135  /** Method for writing continuous buffers to disk.
136  */
137  void writeContinuousBuffer(float* data, int nSamples, int channel);
138 
139  /** Method for writing event buffers to disk.
140  */
141  void writeEventBuffer(MidiMessage& event, int node, int channel);
142 
143  JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (RecordNode);
144 
145 };
146 
147 
148 
149 #endif // __RECORDNODE_H_FB9B1CA7__