improved capture switching and serial midi

This commit is contained in:
langolierz
2018-10-15 15:54:46 +00:00
parent df6851a5a3
commit a17dde7da1
7 changed files with 124 additions and 35 deletions

View File

@@ -21,14 +21,20 @@ class Actions(object):
self.shaders = shaders
self.display = display
self.osc_client = osc_client
self.create_capture_object('value')
self.of_capture = OfCapture(self.tk, self.osc_client, self.message_handler, self.data)
self.python_capture = self.capture = Capture(self.tk, self.message_handler, self.data)
self.capture = None
self.serial_port_process = None
self.set_capture_object('value')
self.server = self.setup_osc_server()
def create_capture_object(self, value):
def set_capture_object(self, value):
if self.data.settings['other']['USE_OF_CAPTURE']['value'] == 'yes':
self.capture = OfCapture(self.tk, self.osc_client, self.message_handler, self.data)
self.python_capture.close_capture()
self.capture = self.of_capture
else:
self.capture = Capture(self.tk, self.message_handler, self.data)
self.python_capture.close_capture()
self.capture = self.python_capture
self.display.capture = self.capture
def move_browser_selection_down(self):
@@ -207,12 +213,6 @@ class Actions(object):
if is_successful and self.video_driver.current_player.status != 'PAUSED':
self.video_driver.current_player.toggle_pause()
## these are temp for testing !
def start_of_capture_preview(self):
self.osc_client.send_message("/capture/start", True)
def stop_of_capture_preview(self):
self.osc_client.send_message("/capture/stop", True)
def toggle_capture_recording(self):
is_recording = self.capture.is_recording
@@ -329,7 +329,7 @@ class Actions(object):
def check_if_should_start_openframeworks(self):
if self.data.settings['other']['VIDEO_BACKEND']['value'] == 'openframeworks':
subprocess.Popen(["make run --directory=~/openFrameworks10/apps/myApps/c_o_n_j_u_r" ], shell=True)
subprocess.Popen(["make run --directory=~/openFrameworks/apps/myApps/c_o_n_j_u_r" ], shell=True)
def exit_openframeworks(self):
self.video_driver.osc_client.send_message("/exit", True)
@@ -431,6 +431,7 @@ class Actions(object):
self.video_driver.exit_all_players()
self.exit_openframeworks()
self.exit_osc_server('','')
self.stop_serial_port_process()
self.toggle_x_autorepeat()
self.tk.destroy()
@@ -499,5 +500,14 @@ class Actions(object):
def exit_osc_server(self, unused_addr, args):
self.server.shutdown()
def create_serial_port_process(self):
if self.serial_port_process == None:
self.serial_port_process = subprocess.Popen("exec " + "ttymidi -s /dev/serial0 -b 38400 -n serial", shell=True)
print('created the serial port process ? {}'.format(self.serial_port_process))
def stop_serial_port_process(self):
if self.serial_port_process is not None:
self.serial_port_process.kill()
self.serial_port_process = None

View File

@@ -0,0 +1,60 @@
# documenting all the steps from old img of recur to working with new features
- gonna start with a `sudo raspi-update` and `sudo apt-get update -y; sudo apt-get upgrade - y`
## setup
to set up for adding things i switched the program to dev mode , connected to the wifi and git fetch from ~/r_e_c_u_r ,
## installing openframeworks and setting up conjur app
i had of10 zipped on a flashdrive already (wget errored about insecure connection when i tried to download from the pi..) , so
- `sudo cp /media/pi/5EB5-664C/of_v0.10.0_linuxarmv6l_release.tar.gz ~/`
- `mkdir openFrameworks` and `tar vxfz of_v0.10.0_linuxarmv6l_release.tar.gz -C openFrameworks --strip-components 1`
- `cd openFrameworks/scripts/linux/debian/` & `sudo ./install_dependencies.sh`
- and also `sudo apt-get upgrade -y; sudo apt-get update` (these took ageeees ! didnt even finish.. will come back to this)
- `make Release -C ~/openFrameworks/libs/openFrameworksCompiled/project`
- `cd ~/openFrameworks/apps/myApps/` and `git clone https://github.com/langolierz/c_o_n_j_u_r.git`
- `cd ~/openFrameworks/addons/` and `git clone https://github.com/langolierz/ofxRPiCameraVideoGrabber` (will swap this out for main once/if my edits work and get in)
- NOTE also gotta checkout the stretch branch : `git checkout stretch`
- `make ~/openFrameworks/apps/myApps/c_o_n_j_u_r
## installing packages and apps
- `sudo pip3 install Adafruit_GPIO Adafruit_MCP3008 RPi.GPIO pivideo python-osc` (tried to install threading but didnt work...)
- (note atleast pivideo needs to be installed with sudo.), also needs `sudo pip3 install serial``
- `sudo apt-get install glslviewer`
### installing ttymidi :
- `wget http://www.varal.org/ttymidi/ttymidi.tar.gz` and `tar -zxvf ttymidi.tar.gz`
- `cd ttymidi` and `sudo nano Makefile` then add `-pthread` after -lasound ...
- then `sudo make` then `sudo make install`
## setup:
need to delete the old settings : `rm json_objects/settings.json` and create a `Shaders` folder,
i think will need to turn on the i2c and serial interfacing... (and maybe that serial switvhing thing .. oh and the clocking for midi serial ... )
these amount to the following in the config:
```
dtparam=i2c_arm=on
dtparam=spi=on
enable_uart=1
```
plus this for serial midi :
```
#setup midi over serial
dtoverlay=pi3-miniuart-bt
dtoverlay=midi-uart0
```

View File

@@ -14,6 +14,18 @@
"control_change 4": {
"DEFAULT": ["set_the_camera_colour_v_continuous"]
},
"control_change 74": {
"DEFAULT": ["set_the_shader_param_0_continuous"]
},
"control_change 71": {
"DEFAULT": ["set_the_shader_param_1_continuous"]
},
"control_change 76": {
"DEFAULT": ["set_the_shader_param_2_continuous"]
},
"control_change 77": {
"DEFAULT": ["set_the_shader_param_3_continuous"]
},
"note_on 72": {
"NAV_BROWSER": ["move_browser_selection_up"],
"PLAYER": ["seek_back_on_player"],

View File

@@ -133,7 +133,7 @@
"value": "dev"
},
"USE_OF_CAPTURE": {
"action": "create_capture_object",
"action": "set_capture_object",
"options": [
"yes",
"no"

View File

@@ -12,26 +12,25 @@ class MidiInput(object):
self.data = data
self.midi_mappings = data.midi_mappings
self.midi_device = None
self.midi_delay = 1
self.serial_port_process = None
self.midi_delay = 40
self.try_open_port()
def try_open_port(self):
midi_setting = self.data.settings['midi']['INPUT']['value']
#print('try open port : midi setting is {}'.format(midi_setting))
if midi_setting == 'usb':
self.stop_serial_port_process()
self.actions.stop_serial_port_process()
self.open_this_port_and_start_listening(20)
elif midi_setting == 'serial':
self.create_serial_port_process()
self.actions.create_serial_port_process()
self.open_this_port_and_start_listening(128)
else:
self.stop_serial_port_process()
self.actions.stop_serial_port_process()
self.root.after(1000, self.try_open_port)
def open_this_port_and_start_listening(self, port_number):
midi_ports = mido.get_input_names()
print('midi ports are {}'.format(midi_ports))
#print('midi ports are {}'.format(midi_ports))
midi_device_on_port = [s for s in midi_ports if '{}:0'.format(port_number) in s]
if midi_device_on_port:
if self.data.midi_status == 'disconnected':
@@ -49,6 +48,7 @@ class MidiInput(object):
i = i + 1
message_dict = message.dict()
midi_channel = midi_setting = self.data.settings['midi']['CHANNEL']['value'] - 1
if not message_dict['channel'] == midi_channel:
pass
## turning off noisey clock messages for now - may want to use them at some point
@@ -57,19 +57,25 @@ class MidiInput(object):
## trying to only let through step cc messages to increase response time
elif message_dict['type'] == 'control_change':
control_number = message_dict['control']
#print('control number is {} , cc_dict.keys is {}'.format(control_number, cc_dict.keys() ))
if not control_number in cc_dict.keys():
cc_dict[control_number] = message_dict['value']
self.on_midi_message(message_dict)
else:
step_size = 4
step_size = 3
ignore_range = range(cc_dict[control_number] - step_size,cc_dict[control_number] + step_size)
#print('value is {} and ignore range is {}'.format(message_dict['value'], ignore_range ))
if not message_dict['value'] in ignore_range:
cc_dict[control_number] = message_dict['value']
#print(message_dict)
self.on_midi_message(message_dict)
print(cc_dict)
#print(cc_dict)
else:
self.on_midi_message(message_dict)
if i > 0:
print('the number processed {}'.format(i))
pass
#print('the number processed {}'.format(i))
self.root.after(self.midi_delay, self.poll_midi_input)
def on_midi_message(self, message_dict):
@@ -105,6 +111,7 @@ class MidiInput(object):
print('the action being called is {}'.format(method_name))
if mapped_message_value is not None:
norm_message_value = mapped_message_value/127
else:
norm_message_value = None
self.call_method_name(method_name, norm_message_value)
@@ -118,15 +125,7 @@ class MidiInput(object):
else:
getattr(self.actions, method_name)()
def create_serial_port_process(self):
if self.serial_port_process == None:
self.serial_port_process = subprocess.Popen("exec " + "ttymidi -s /dev/serial0 -b 38400 -n serial", shell=True)
print('created the serial port process ? {}'.format(self.serial_port_process))
def stop_serial_port_process(self):
if self.serial_port_process is not None:
self.serial_port_process.kill()
self.serial_port_process = None

View File

@@ -245,5 +245,10 @@ class Capture(object):
def receive_state(self, unused_addr, args):
pass
def close_capture(self):
if self.device is not None:
print('closing the old camera...')
self.device.close()

View File

@@ -24,8 +24,8 @@ class OfCapture(object):
print('its picapture with no source !')
return False
self.update_capture_settings()
if not self.check_if_attached_with_picamera():
return
#if not self.check_if_attached_with_picamera():
# return
print('sending setup message !')
self.osc_client.send_message("/capture/setup", True)
# try:
@@ -63,6 +63,7 @@ class OfCapture(object):
#self.device.resolution = self.resolution
def check_if_attached_with_picamera(self):
print('about to try open pcamera to check..')
try:
device = picamera.PiCamera(resolution=self.resolution, framerate=self.framerate, sensor_mode = self.sensor_mode)
device.close()
@@ -218,12 +219,14 @@ class OfCapture(object):
return int(fractions.Fraction(setting_value) * 1000000)
def receive_state(self, unused_addr, args):
if args:
if args == 1.0:
self.has_capture = True
self.message_handler.set_message('INFO', 'capture device attached')
else:
self.has_capture = False
self.message_handler.set_message('INFO', 'no capture device attached')
print('the has capture is set to {}'.format(self.has_capture))
def close_capture(self):
pass