Skip to content

Commit

Permalink
Merge commit 'refs/pull/149/merge' of github.com:marcelog/PAMI into PR
Browse files Browse the repository at this point in the history
Add format and mix parameters to MonitorAction.php

Small fix to follow to marcelogs directive

PR: Created by @syco (marcelog#149)
  • Loading branch information
dkgroot committed Apr 24, 2019
2 parents 1cd0486 + 1190995 commit b5d244f
Show file tree
Hide file tree
Showing 3 changed files with 107 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/PAMI/Message/Action/MonitorAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,30 @@ public function __construct($channel, $filename)
{
parent::__construct('Monitor');
$this->setKey('Channel', $channel);
$this->setKey('Mix', 'true');
$this->setKey('Format', 'wav');
$this->setKey('File', $filename);
}

/**
* Sets Format
*
* @param string $format Format to be used during recording
*
* @return void
*/
public function setFormat($format)
{
$this->setKey('Format', $format);
}

/**
* Sets mixing true/false
*
* @param boolean $monitor Switch mixing mode on/off.
*
* @return void
*/
public function setFormat($mix)
{
$this->setKey('Mix', $mix ? 'true' : 'false');
}
}
14 changes: 14 additions & 0 deletions src/PAMI/Message/Action/StatusAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,18 @@ public function __construct($channel = false)
$this->setKey('Channel', $channel);
}
}

/**
* Sets Variables key.
*
* @param array $variables Variables to use.
*
* @return void
*/
public function setVariables($variables = array())
{
if (!empty($variables)) {
$this->setKey('Variables', implode(',', $variables));
}
}
}
69 changes: 69 additions & 0 deletions src/PAMI/Message/IncomingMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ abstract class IncomingMessage extends Message
*/
protected $channelVariables;

/**
* Metadata. Specific channel variables.
* @var string[]
*/
protected $statusVariables;

/**
* Serialize function.
*
Expand Down Expand Up @@ -125,6 +131,45 @@ public function getChannelVariables($channel = null)
}
}

/**
* Returns the channel variables for all reported channels.
* https://github.com/marcelog/PAMI/issues/85
*
* The channel names will be lowercased.
*
* @return array
*/
public function getAllStatusVariables()
{
return $this->statusVariables;
}

/**
* Returns the channel variables for the given channel.
* https://github.com/marcelog/PAMI/issues/85
*
* @param string $channel Channel name. If not given, will return variables
* for the "current" channel.
*
* @return array
*/
public function getStatusVariables($channel = null)
{
if (is_null($channel)) {
if (!isset($this->keys['channel'])) {
return $this->getStatusVariables('default');
} else {
return $this->getStatusVariables($this->keys['channel']);
}
} else {
$channel = strtolower($channel);
if (!isset($this->statusVariables[$channel])) {
return null;
}
return $this->statusVariables[$channel];
}
}

/**
* Constructor.
*
Expand All @@ -136,6 +181,7 @@ public function __construct($rawContent)
{
parent::__construct();
$this->channelVariables = array('default' => array());
$this->statusVariables = array('default' => array());
$this->rawContent = $rawContent;
$lines = explode(Message::EOL, $rawContent);
foreach ($lines as $line) {
Expand All @@ -155,6 +201,18 @@ public function __construct($rawContent)
unset($content[0]);
$value = isset($content[1]) ? trim(implode(':', $content)) : '';
$this->channelVariables[$chanName][$name] = $value;
} else if (!strncmp($name, 'variable', 8)) {
// https://github.com/marcelog/PAMI/issues/85
$matches = preg_match("/\(([^\)]*)\)/", $name, $captures);
$chanName = 'default';
if ($matches > 0) {
$chanName = $captures[1];
}
$content = explode('=', $value);
$name = strtolower(trim($content[0]));
unset($content[0]);
$value = isset($content[1]) ? trim(implode(':', $content)) : '';
$this->statusVariables[$chanName][$name] = $value;
} else {
$this->setKey($name, $value);
}
Expand All @@ -168,6 +226,7 @@ public function __construct($rawContent)
// https://github.com/marcelog/PAMI/issues/85
if (isset($this->keys['channel'])) {
$channel = strtolower($this->keys['channel']);

if (isset($this->channelVariables[$channel])) {
$this->channelVariables[$channel] = array_merge(
$this->channelVariables[$channel],
Expand All @@ -177,6 +236,16 @@ public function __construct($rawContent)
$this->channelVariables[$channel] = $this->channelVariables['default'];
}
unset($this->channelVariables['default']);

if (isset($this->statusVariables[$channel])) {
$this->statusVariables[$channel] = array_merge(
$this->statusVariables[$channel],
$this->statusVariables['default']
);
} else {
$this->statusVariables[$channel] = $this->statusVariables['default'];
}
unset($this->statusVariables['default']);
}
}
}

0 comments on commit b5d244f

Please sign in to comment.