-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
87ae47b
commit 8f882c1
Showing
5 changed files
with
136 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import os | ||
|
||
def concatenate_files(dir_path, output_file): | ||
""" | ||
Concatenates the content of all text files located in the directory and sub-directories. | ||
:param dir_path: String, path of the directory to search for files to concatenate. | ||
:param output_file: String, path of the file where all content will be saved. | ||
""" | ||
with open(output_file, 'w') as outfile: # Opening the file that will hold all the contents. | ||
for root, dirs, files in os.walk(dir_path): # Traversing directory tree. | ||
print(files) | ||
for filename in files: | ||
filepath = os.path.join(root, filename) # Creating full path to the file. | ||
try: | ||
with open(filepath, 'r') as readfile: # Opening each file safely with 'with'. | ||
content = readfile.read() | ||
outfile.write("Content of " + filepath + ":\n" + content + "\n") # Writing content followed by a newline. | ||
except Exception as e: | ||
print(f"Failed to read file {filepath}: {e}") | ||
|
||
# Usage | ||
# directory_path = '~/membrane/membrane_core' # Set your directory path here. | ||
directory_path = os.getcwd() + "/lib" | ||
output_path = 'combined_output.txt' | ||
concatenate_files(directory_path, output_path) | ||
|
||
print(f"All files have been concatenated into {output_path}.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
# Timer usage examples | ||
Exampls below illustrate how to use `:start_timer`, `:timer_interval` and `:stop_timer` actions on the example of `Membrane.Source`, but the API looks the same for all kinds of the Membrane Components | ||
|
||
### Emit empty buffer every 100 milliseconds | ||
```elixir | ||
defmodule MySource do | ||
use Membrane.Source | ||
|
||
def_output_pad :output, accepted_format: SomeFormat | ||
|
||
@impl true | ||
def handle_init(_ctx, _opts), do: {[], %{}} | ||
|
||
@impl true | ||
def handle_playing(_ctx, state) do | ||
interval_in_millis = 100 | ||
interval = Membrane.Time.milliseconds(interval_in_millis) | ||
|
||
actions = [ | ||
stream_format: %SomeFormat{}, | ||
start_timer: {:some_timer, interval} | ||
] | ||
|
||
{actions, state} | ||
end | ||
|
||
@impl true | ||
def handle_tick(:some_timer, _ctx, state) do | ||
buffer = %Membrane.Buffer{payload: ""} | ||
actions = [buffer: {:output, buffer}] | ||
{actions, state} | ||
end | ||
end | ||
``` | ||
|
||
### Emit empty buffer every 100 millisecond if parent hasn't stopped you | ||
The source below accepts following notifications from the parent: | ||
- `:pause` - after receiving it the source will pause sending buffers. The paused soure can be resumed again. | ||
- `:resume` - resumes sending buffers from the paused source. | ||
- `:stop` - the stopped source won't send any buffer again. | ||
|
||
```elixir | ||
defmodule MyComplexSource | ||
use Membrane.Source | ||
|
||
def_output_pad :output, accepted_format: SomeFormat | ||
|
||
@one_hundred_millis = Membrane.Time.milliseconds(100) | ||
|
||
@impl true | ||
def handle_init(_ctx, _opts), do: {[], %{status: nil}} | ||
|
||
@impl true | ||
def handle_playing(_ctx, state) do | ||
interval_in_millis = 100 | ||
interval = Membrane.Time.milliseconds(interval_in_millis) | ||
|
||
actions = [ | ||
stream_format: %SomeFormat{}, | ||
start_timer: {:some_timer, interval} | ||
] | ||
|
||
{actions, %{state | status: :resumed}} | ||
end | ||
|
||
@impl true | ||
def handle_parent_notification(notification, ctx, _state) when ctx.playback == :stopped do | ||
raise "Cannot handle parent notification: #{inspect(notification)} before handle_palaying" | ||
end | ||
|
||
@impl true | ||
def handle_parent_notification(notification, _ctx, state) when notification in [:pause, :resume, :stop] do | ||
case notification do | ||
:pause when state.status == :resumed -> | ||
{[], %{state | status: :pause_on_next_handle_tick}} | ||
|
||
:resume when state.status == :paused -> | ||
actions = [timer_interval: {:some_timer, @one_hundred_millis}] | ||
{actions, %{state | status: :resumed}} | ||
|
||
:resume when state.status == :pause_on_next_handle_tick -> | ||
{[], %{state | status: :resumed}} | ||
|
||
:stop -> | ||
{[stop_timer: :some_timer], %{state | status: :stopped}} | ||
end | ||
end | ||
|
||
@impl true | ||
def handle_tick(:some_timer, _ctx, state) do | ||
case state.status do | ||
:resumed -> | ||
buffer = %Membrane.Buffer{payload: ""} | ||
{[buffer: {:output, buffer}], state} | ||
|
||
:pause_on_next_handle_tick -> | ||
actions = [timer_interval: :no_interval] | ||
{actions, %{state | status: :paused}} | ||
end | ||
end | ||
end | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters