Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
stuerp committed Dec 2, 2024
1 parent 1c31c14 commit 0faa928
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 79 deletions.
56 changes: 28 additions & 28 deletions PlaylistTemplate.html
Original file line number Diff line number Diff line change
Expand Up @@ -312,28 +312,22 @@
document.getElementById("onPlaylistItemsRemovedResult").textContent = "Items " + removedItems + " removed from playlist " + playlistIndex + " (" + Now() + ")";
}

// Called when the selected items changed.
function onPlaylistSelectedItemsChanged(playlistIndex, selection)
{
document.getElementById("onPlaylistSelectedItemsChangedResult").textContent = "Selected items changed to " + selection + " in playlist " + playlistIndex + " (" + Now() + ")";
}

// Called when some playlist items of the specified playlist have been modified.
function onPlaylistItemsModified(playlistIndex)
function onPlaylistItemsModified(playlistIndex, items)
{
document.getElementById("onPlaylistItemsModifiedResult").textContent = "Some playlist items have been modified in playlist " + playlistIndex + " (" + Now() + ")";
document.getElementById("onPlaylistItemsModifiedResult").textContent = "Playlist items " + items + " have been modified in playlist " + playlistIndex + " (" + Now() + ")";
}

// Called when some playlist items of the specified playlist have been modified from playback.
function onPlaylistItemsModifiedFromPlayback(playlistIndex)
function onPlaylistItemsModifiedFromPlayback(playlistIndex, items)
{
document.getElementById("onPlaylistItemsModifiedFromPlaybackResult").textContent = "Some playlist items have been modified from playback in playlist " + playlistIndex + " (" + Now() + ")";
document.getElementById("onPlaylistItemsModifiedFromPlaybackResult").textContent = "Playlist items " + items + " have been modified from playback in playlist " + playlistIndex + " (" + Now() + ")";
}

// Called when items of the specified playlist have been replaced.
function onPlaylistItemsReplaced(playlistIndex)
function onPlaylistItemsReplaced(playlistIndex, items)
{
document.getElementById("onPlaylistItemsReplacedResult").textContent = "Playlist items have been replaced in playlist " + playlistIndex + " (" + Now() + ")";
document.getElementById("onPlaylistItemsReplacedResult").textContent = "Playlist items " + items + "have been replaced in playlist " + playlistIndex + " (" + Now() + ")";
}

// Called when the specified item of a playlist has been ensured to be visible.
Expand All @@ -342,58 +336,64 @@
document.getElementById("onPlaylistItemEnsureVisibleResult").textContent = "Ensured item " + itemIndex + " in playlist " + playlistIndex + " (" + Now() + ")";
}

// Called when the active playlist changes.
function onPlaylistActivated(oldPlaylistIndex, newPlaylistIndex)
{
document.getElementById("onPlaylistActivatedResult").textContent = "Active playlist changed from " + oldPlaylistIndex + " to " + newPlaylistIndex + " (" + Now() + ")";
}

// Called when a new playlist has been created.
function onPlaylistCreated(playlistIndex, name)
{
document.getElementById("onPlaylistCreatedResult").textContent = "Created playlist " + playlistIndex + " as \"" + name + "\" (" + Now() + ")";
}

/// Called when the specified playlist has been renamed.
// Called when the specified playlist has been renamed.
function onPlaylistRenamed(playlistIndex, name)
{
document.getElementById("onPlaylistRenamedResult").textContent = "Playlist " + playlistIndex + " renamed to \"" + name + "\" (" + Now() + ")";
}

/// Called when the specified playlist has been locked.
// Called when the active playlist changes.
function onPlaylistActivated(oldPlaylistIndex, newPlaylistIndex)
{
document.getElementById("onPlaylistActivatedResult").textContent = "Active playlist changed from " + oldPlaylistIndex + " to " + newPlaylistIndex + " (" + Now() + ")";
}

// Called when the specified playlist has been locked.
function onPlaylistLocked(playlistIndex)
{
document.getElementById("onPlaylistLockedResult").textContent = "Playlist " + playlistIndex + " has been locked (" + Now() + ")";
}

/// Called when the specified playlist has been locked.
// Called when the specified playlist has been locked.
function onPlaylistUnlocked(playlistIndex)
{
document.getElementById("onPlaylistUnlockedResult").textContent = "Playlist " + playlistIndex + " has been unlocked (" + Now() + ")";
}

// Called when the selected items changed.
function onPlaylistSelectedItemsChanged(playlistIndex, selectedItems)
{
document.getElementById("onPlaylistSelectedItemsChangedResult").textContent = "Selected items changed to " + selectedItems + " in playlist " + playlistIndex + " (" + Now() + ")";
}

// Called when the focused item of a playlist changed.
function onPlaylistFocusedItemChanged(playlistIndex, fromIndex, toIndex)
{
document.getElementById("onPlaylistFocusedItemChangedResult").textContent = "Focused item changed from " + fromIndex + " to " + toIndex + " in playlist " + playlistIndex + " (" + Now() + ")";
}

// Called when the playlists have beenn reordered.
function onPlaylistsReordered()
// Called when the playlists have been reordered.
function onPlaylistsReordered(playlistOrder)
{
document.getElementById("onPlaylistsReorderedResult").textContent = "Playlists have been reordered (" + Now() + ")";
document.getElementById("onPlaylistsReorderedResult").textContent = "Playlists " + playlistOrder + " have been reordered (" + Now() + ")";
}

// Called when playlists are being removed.
function onPlaylistsRemoving()
function onPlaylistsRemoving(removedPlaylists, newCount)
{
document.getElementById("onPlaylistsRemovingResult").textContent = "Playlists are being removed (" + Now() + ")";
document.getElementById("onPlaylistsRemovingResult").textContent = "Playlists " + removedPlaylists + " are being removed (" + Now() + ")";
}

/// Called when playlists have been removed.
function onPlaylistsRemoved()
function onPlaylistsRemoved(removedPlaylists, newCount)
{
document.getElementById("onPlaylistsRemovedResult").textContent = "Playlists have been removed (" + Now() + ")";
document.getElementById("onPlaylistsRemovedResult").textContent = "Playlists " + removedPlaylists + " have been removed (" + Now() + ")";
}

/// Called when the default format has been changed.
Expand Down
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,9 @@ v0.2.0.0-alpha5, 2024-12-xx, *"I'm getting framed..."*
* onPlaylistItemsReordered(playlistIndex, items): Called when the items of the specified playlist have been reordered. (alpha5)
* onPlaylistItemsRemoving(playlistIndex, removedItems, newCount): Called when removing items of the specified playlist. (alpha5)
* onPlaylistItemsRemoved(playlistIndex, removedItems, newCount): Called when items of the specified playlist have been removed. (alpha5)
* onPlaylistItemsModified(playlistIndex): Called when some playlist items of the specified playlist have been modified. (alpha4)
* onPlaylistItemsModifiedFromPlayback(playlistIndex): Called when some playlist items of the specified playlist have been modified from playback. (alpha4)
* onPlaylistItemsReplaced(playlistIndex): Called when items of the specified playlist have been replaced. (alpha4)
* onPlaylistItemsModified(playlistIndex, items): Called when some playlist items of the specified playlist have been modified. (alpha5)
* onPlaylistItemsModifiedFromPlayback(playlistIndex, items): Called when some playlist items of the specified playlist have been modified from playback. (alpha5)
* onPlaylistItemsReplaced(playlistIndex, items): Called when items of the specified playlist have been replaced. (alpha5)

* onPlaylistItemEnsureVisible(playlistIndex, itemIndex): Called when the specified item of a playlist was ensured to be visible. (alpha4)

Expand All @@ -160,12 +160,12 @@ v0.2.0.0-alpha5, 2024-12-xx, *"I'm getting framed..."*
* onPlaylistActivated(oldPlaylistIndex, newPlaylistIndex): Called when the active playlist is changed. (alpha4)
* onPlaylistLocked(playlistIndex): Called when the specified playlist has been locked. (alpha4)
* onPlaylistUnlocked(playlistIndex): Called when the specified playlist has been unlocked. (alpha4)
* onPlaylistSelectedItemsChanged(playlistIndex): Called when the selected items of the specified playlist have been changed. (alpha4)
* onPlaylistSelectedItemsChanged(playlistIndex, selectedItems): Called when the selected items of the specified playlist have been changed. (alpha5)
* onPlaylistFocusedItemChanged(playlistIndex, fromItemIndex, toItemIndex): Called when the focused item of the specified playlist has been changed. (alpha4)

* onPlaylistsReordered(): Called when the playlists have been reordered. (alpha4)
* onPlaylistsRemoving(): Called when playlists are being removed. (alpha4)
* onPlaylistsRemoved(): Called when playlists have been removed. (alpha4)
* onPlaylistsReordered(playlistOrder): Called when the playlists have been reordered. (alpha5)
* onPlaylistsRemoving(removedPlaylists, newCount): Called when playlists are being removed. (alpha5)
* onPlaylistsRemoved(removedPlaylists, newCount): Called when playlists have been removed. (alpha5)

* onDefaultFormatChanged(): Called when the default format has been changed. (alpha4)
* onPlaybackOrderChanged(playbackOrderIndex): Called when the playback order has been changed. (alpha4)
Expand All @@ -177,6 +177,7 @@ v0.2.0.0-alpha5, 2024-12-xx, *"I'm getting framed..."*
* Changed: Returned JSON objects now use camelCase casing. (alpha4)
* Changed: *Breaking Change* Callbacks follow the Category-Noun-Verb naming convention. (alpha5)
* Changed: *Breaking Change* All properties, methods and callbacks to use camelCase convention. (alpha5)
* Changed: *Breaking Change* The parameter list of most callbacks has been expanded. (alpha5)

v0.1.8.0, 2024-08-10

Expand Down
104 changes: 60 additions & 44 deletions UIElementPlaylistCallback.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

/** $VER: UIElement.cpp (2024.12.02) P. Stuer **/
/** $VER: UIElementPlaylistCallback.cpp (2024.12.02) P. Stuer **/

#include "pch.h"

Expand All @@ -9,10 +9,6 @@
#include "Exceptions.h"
#include "Support.h"

#include <pathcch.h>

#pragma comment(lib, "pathcch")

#include <SDK/titleformat.h>
#include <SDK/playlist.h>
#include <SDK/ui.h>
Expand All @@ -36,9 +32,9 @@ void UIElement::on_items_added(t_size playlistIndex, t_size startIndex, metadb_h
/// <summary>
/// Called when the items of the specified playlist have been reordered.
/// </summary>
void UIElement::on_items_reordered(t_size playlistIndex, const t_size * order, t_size count)
void UIElement::on_items_reordered(t_size playlistIndex, const t_size * itemOrder, t_size itemCount)
{
const std::wstring Text = ToJSON(order, count);
const std::wstring Text = ToJSON(itemOrder, itemCount);

const std::wstring Script = ::FormatText(L"onPlaylistItemsReordered(%d, \"%s\")", (int) playlistIndex, Text.c_str());

Expand Down Expand Up @@ -70,63 +66,73 @@ void UIElement::on_items_removed(t_size playlistIndex, const bit_array & mask, t
}

/// <summary>
/// Called when the selected items changed.
/// Called when some playlist items of the specified playlist have been modified.
/// </summary>
void UIElement::on_items_selection_change(t_size playlistIndex, const bit_array & affectedItems, const bit_array & state)
void UIElement::on_items_modified(t_size playlistIndex, const bit_array & mask)
{
const std::wstring Text = ToJSON(affectedItems, ~0);
t_size ItemCount = playlist_manager_v4::get()->playlist_get_item_count(playlistIndex);

const std::wstring Script = ::FormatText(L"onPlaylistSelectedItemsChanged(%d, \"%s\")", (int) playlistIndex, Text.c_str());
const std::wstring Text = ToJSON(mask, ItemCount);

const std::wstring Script = ::FormatText(L"onPlaylistItemsModified(%d, \"%s\")", (int) playlistIndex, Text.c_str());

ExecuteScript(Script);
}

/// <summary>
/// Called when the focused item of a playlist changed.
/// Called when some playlist items of the specified playlist have been modified from playback.
/// </summary>
void UIElement::on_item_focus_change(t_size playlistIndex, t_size fromIndex, t_size toIndex)
void UIElement::on_items_modified_fromplayback(t_size playlistIndex, const bit_array & mask, play_control::t_display_level displayLevel)
{
const std::wstring Script = ::FormatText(L"onPlaylistFocusedItemChanged(%d, %d, %d)", (int) playlistIndex, (int) fromIndex, (int) toIndex);
t_size ItemCount = playlist_manager_v4::get()->playlist_get_item_count(playlistIndex);

const std::wstring Text = ToJSON(mask, ItemCount);

const std::wstring Script = ::FormatText(L"onPlaylistItemsModifiedFromPlayback(%d, \"%s\")", (int) playlistIndex, Text.c_str());

ExecuteScript(Script);
}

/// <summary>
/// Called when the specified item of a playlist has been ensured to be visible.
/// Called when items of the specified playlist have been replaced.
/// </summary>
void UIElement::on_item_ensure_visible(t_size playlistIndex, t_size itemIndex)
void UIElement::on_items_replaced(t_size playlistIndex, const bit_array & mask, const pfc::list_base_const_t<playlist_callback::t_on_items_replaced_entry> & replacedItems)
{
const std::wstring Script = ::FormatText(L"onPlaylistItemEnsureVisible(%d, %d)", (int) playlistIndex, (int) itemIndex);
t_size ItemCount = playlist_manager_v4::get()->playlist_get_item_count(playlistIndex);

const std::wstring Text = ToJSON(mask, ItemCount);

const std::wstring Script = ::FormatText(L"onPlaylistItemsReplaced(%d, \"%s\")", (int) playlistIndex, Text.c_str());

ExecuteScript(Script);
}

/// <summary>
/// Called when some playlist items of the specified playlist have been modified.
/// Called when the specified item of a playlist has been ensured to be visible.
/// </summary>
void UIElement::on_items_modified(t_size playlistIndex, const bit_array & mask)
void UIElement::on_item_ensure_visible(t_size playlistIndex, t_size itemIndex)
{
const std::wstring Script = ::FormatText(L"onPlaylistItemsModified(%d)", (int) playlistIndex);
const std::wstring Script = ::FormatText(L"onPlaylistItemEnsureVisible(%d, %d)", (int) playlistIndex, (int) itemIndex);

ExecuteScript(Script);
}

/// <summary>
/// Called when some playlist items of the specified playlist have been modified from playback.
/// Called when a new playlist has been created.
/// </summary>
void UIElement::on_items_modified_fromplayback(t_size playlistIndex, const bit_array & mask, play_control::t_display_level displayLevel)
void UIElement::on_playlist_created(t_size playlistIndex, const char * name, t_size size)
{
const std::wstring Script = ::FormatText(L"onPlaylistItemsModifiedFromPlayback(%d)", (int) playlistIndex);
const std::wstring Script = ::FormatText(L"onPlaylistCreated(%d, \"%s\")", (int) playlistIndex, ::UTF8ToWide(name, size).c_str());

ExecuteScript(Script);
}

/// <summary>
/// Called when items of the specified playlist have been replaced.
/// Called when the specified playlist has been renamed.
/// </summary>
void UIElement::on_items_replaced(t_size playlistIndex, const bit_array & mask, const pfc::list_base_const_t<playlist_callback::t_on_items_replaced_entry> & replacedItems)
void UIElement::on_playlist_renamed(t_size playlistIndex, const char * name, t_size size)
{
const std::wstring Script = ::FormatText(L"onPlaylistItemsReplaced(%d)", (int) playlistIndex);
const std::wstring Script = ::FormatText(L"onPlaylistRenamed(%d, \"%s\")", (int) playlistIndex, ::UTF8ToWide(name, size).c_str());

ExecuteScript(Script);
}
Expand All @@ -142,61 +148,71 @@ void UIElement::on_playlist_activate(t_size oldPlaylistIndex, t_size newPlaylist
}

/// <summary>
/// Called when a new playlist has been created.
/// Called when the specified playlist has been locked or unlocked.
/// </summary>
void UIElement::on_playlist_created(t_size playlistIndex, const char * name, t_size size)
void UIElement::on_playlist_locked(t_size playlistIndex, bool isLocked)
{
const std::wstring Script = ::FormatText(L"onPlaylistCreated(%d, \"%s\")", (int) playlistIndex, ::UTF8ToWide(name, size).c_str());
const std::wstring Script = ::FormatText(isLocked ? L"onPlaylistLocked(%d)" : L"onPlaylistUnlocked(%d)", (int) playlistIndex);

ExecuteScript(Script);
}

/// <summary>
/// Called when the playlists have beenn reordered.
/// Called when the selected items changed.
/// </summary>
void UIElement::on_playlists_reorder(const t_size * order, t_size count)
void UIElement::on_items_selection_change(t_size playlistIndex, const bit_array & affectedItems, const bit_array & state)
{
const std::wstring Script = L"onPlaylistsReordered()";
t_size ItemCount = playlist_manager_v4::get()->playlist_get_item_count(playlistIndex);

const std::wstring Text = ToJSON(affectedItems, ItemCount);

const std::wstring Script = ::FormatText(L"onPlaylistSelectedItemsChanged(%d, \"%s\")", (int) playlistIndex, Text.c_str());

ExecuteScript(Script);
}

/// <summary>
/// Called when playlists are being removed.
/// Called when the focused item of a playlist changed.
/// </summary>
void UIElement::on_playlists_removing(const bit_array & mask, t_size oldCount, t_size newCount)
void UIElement::on_item_focus_change(t_size playlistIndex, t_size fromIndex, t_size toIndex)
{
const std::wstring Script = L"onPlaylistsRemoving()";
const std::wstring Script = ::FormatText(L"onPlaylistFocusedItemChanged(%d, %d, %d)", (int) playlistIndex, (int) fromIndex, (int) toIndex);

ExecuteScript(Script);
}

/// <summary>
/// Called when playlists have been removed.
/// Called when the playlists have beenn reordered.
/// </summary>
void UIElement::on_playlists_removed(const bit_array & mask, t_size oldCount, t_size newcount)
void UIElement::on_playlists_reorder(const t_size * playlistOrder, t_size playlistCount)
{
const std::wstring Script = L"onPlaylistsRemoved()";
const std::wstring Text = ToJSON(playlistOrder, playlistCount);

const std::wstring Script = ::FormatText(L"onPlaylistsReordered(\"%s\")", Text.c_str());

ExecuteScript(Script);
}

/// <summary>
/// Called when the specified playlist has been renamed.
/// Called when playlists are being removed.
/// </summary>
void UIElement::on_playlist_renamed(t_size playlistIndex, const char * name, t_size size)
void UIElement::on_playlists_removing(const bit_array & mask, t_size oldCount, t_size newCount)
{
const std::wstring Script = ::FormatText(L"onPlaylistRenamed(%d, \"%s\")", (int) playlistIndex, ::UTF8ToWide(name, size).c_str());
const std::wstring Text = ToJSON(mask, oldCount);

const std::wstring Script = ::FormatText(L"onPlaylistsRemoving(\"%s\", %d)", Text.c_str(), (int) newCount);

ExecuteScript(Script);
}

/// <summary>
/// Called when the specified playlist has been locked or unlocked.
/// Called when playlists have been removed.
/// </summary>
void UIElement::on_playlist_locked(t_size playlistIndex, bool isLocked)
void UIElement::on_playlists_removed(const bit_array & mask, t_size oldCount, t_size newCount)
{
const std::wstring Script = ::FormatText(isLocked ? L"onPlaylistLocked(%d)" : L"onPlaylistUnlocked(%d)", (int) playlistIndex);
const std::wstring Text = ToJSON(mask, oldCount);

const std::wstring Script = ::FormatText(L"onPlaylistsRemoved(\"%s\", %d)", Text.c_str(), (int) newCount);

ExecuteScript(Script);
}
Expand Down

0 comments on commit 0faa928

Please sign in to comment.